Mercurial > vim
annotate src/ex_cmds.c @ 14185:20468fb49f9b v8.1.0110
patch 8.1.0110: file name not displayed with ":file"
commit https://github.com/vim/vim/commit/fc0896093c3b3e753859a5f929921933e7a2e6cd
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jun 24 16:53:35 2018 +0200
patch 8.1.0110: file name not displayed with ":file"
Problem: File name not displayed with ":file" when 'F' is in 'shortmess'.
Solution: Always display the file name when there is no argument (Christian
Brabandt, closes #3070)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 24 Jun 2018 17:00:06 +0200 |
parents | 2ad722003b36 |
children | 6fbb8dfb3389 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
10021
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 | |
10 /* | |
11 * ex_cmds.c: some functions for command line commands | |
12 */ | |
13 | |
14 #include "vim.h" | |
15 #include "version.h" | |
16 | |
7691
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
17 #ifdef FEAT_FLOAT |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
18 # include <float.h> |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
19 #endif |
fd4175b669e2
commit https://github.com/vim/vim/commit/17576a1e33d71b5602cee86bf220a806c8412605
Christian Brabandt <cb@256bit.org>
parents:
7689
diff
changeset
|
20 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
21 static int linelen(int *has_tab); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
22 static void do_filter(linenr_T line1, linenr_T line2, exarg_T *eap, char_u *cmd, int do_in, int do_out); |
7 | 23 #ifdef FEAT_VIMINFO |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
24 static char_u *viminfo_filename(char_u *); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
25 static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
26 static int viminfo_encoding(vir_T *virp); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
27 static int read_viminfo_up_to_marks(vir_T *virp, int forceit, int writing); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
28 #endif |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
29 |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
30 static int check_readonly(int *forceit, buf_T *buf); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
31 static void delbuf_msg(char_u *name); |
7 | 32 static int |
33 #ifdef __BORLANDC__ | |
34 _RTLENTRYF | |
35 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
36 help_compare(const void *s1, const void *s2); |
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
37 static void prepare_help_buffer(void); |
7 | 38 |
39 /* | |
40 * ":ascii" and "ga". | |
41 */ | |
42 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
43 do_ascii(exarg_T *eap UNUSED) |
7 | 44 { |
45 int c; | |
1784 | 46 int cval; |
7 | 47 char buf1[20]; |
48 char buf2[20]; | |
49 char_u buf3[7]; | |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
50 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
51 char_u *dig; |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
52 #endif |
7 | 53 #ifdef FEAT_MBYTE |
714 | 54 int cc[MAX_MCO]; |
55 int ci = 0; | |
7 | 56 int len; |
57 | |
58 if (enc_utf8) | |
714 | 59 c = utfc_ptr2char(ml_get_cursor(), cc); |
7 | 60 else |
61 #endif | |
62 c = gchar_cursor(); | |
63 if (c == NUL) | |
64 { | |
65 MSG("NUL"); | |
66 return; | |
67 } | |
68 | |
69 #ifdef FEAT_MBYTE | |
70 IObuff[0] = NUL; | |
71 if (!has_mbyte || (enc_dbcs != 0 && c < 0x100) || c < 0x80) | |
72 #endif | |
73 { | |
74 if (c == NL) /* NUL is stored as NL */ | |
75 c = NUL; | |
1784 | 76 if (c == CAR && get_fileformat(curbuf) == EOL_MAC) |
77 cval = NL; /* NL is stored as CR */ | |
78 else | |
79 cval = c; | |
7 | 80 if (vim_isprintc_strict(c) && (c < ' ' |
81 #ifndef EBCDIC | |
82 || c > '~' | |
83 #endif | |
84 )) | |
85 { | |
86 transchar_nonprint(buf3, c); | |
1872 | 87 vim_snprintf(buf1, sizeof(buf1), " <%s>", (char *)buf3); |
7 | 88 } |
89 else | |
90 buf1[0] = NUL; | |
91 #ifndef EBCDIC | |
92 if (c >= 0x80) | |
1872 | 93 vim_snprintf(buf2, sizeof(buf2), " <M-%s>", |
94 (char *)transchar(c & 0x7f)); | |
7 | 95 else |
96 #endif | |
97 buf2[0] = NUL; | |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
98 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
99 dig = get_digraph_for_char(cval); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
100 if (dig != NULL) |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
101 vim_snprintf((char *)IObuff, IOSIZE, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
102 _("<%s>%s%s %d, Hex %02x, Oct %03o, Digr %s"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
103 transchar(c), buf1, buf2, cval, cval, cval, dig); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
104 else |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
105 #endif |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
106 vim_snprintf((char *)IObuff, IOSIZE, |
274 | 107 _("<%s>%s%s %d, Hex %02x, Octal %03o"), |
1784 | 108 transchar(c), buf1, buf2, cval, cval, cval); |
7 | 109 #ifdef FEAT_MBYTE |
963 | 110 if (enc_utf8) |
111 c = cc[ci++]; | |
112 else | |
113 c = 0; | |
7 | 114 #endif |
115 } | |
116 | |
117 #ifdef FEAT_MBYTE | |
118 /* Repeat for combining characters. */ | |
119 while (has_mbyte && (c >= 0x100 || (enc_utf8 && c >= 0x80))) | |
120 { | |
121 len = (int)STRLEN(IObuff); | |
122 /* This assumes every multi-byte char is printable... */ | |
123 if (len > 0) | |
124 IObuff[len++] = ' '; | |
125 IObuff[len++] = '<'; | |
963 | 126 if (enc_utf8 && utf_iscomposing(c) |
625 | 127 # ifdef USE_GUI |
7 | 128 && !gui.in_use |
625 | 129 # endif |
7 | 130 ) |
131 IObuff[len++] = ' '; /* draw composing char on top of a space */ | |
274 | 132 len += (*mb_char2bytes)(c, IObuff + len); |
13359
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
133 #ifdef FEAT_DIGRAPHS |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
134 dig = get_digraph_for_char(c); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
135 if (dig != NULL) |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
136 vim_snprintf((char *)IObuff + len, IOSIZE - len, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
137 c < 0x10000 ? _("> %d, Hex %04x, Oct %o, Digr %s") |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
138 : _("> %d, Hex %08x, Oct %o, Digr %s"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
139 c, c, c, dig); |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
140 else |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
141 #endif |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
142 vim_snprintf((char *)IObuff + len, IOSIZE - len, |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
143 c < 0x10000 ? _("> %d, Hex %04x, Octal %o") |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
144 : _("> %d, Hex %08x, Octal %o"), |
81c348d40312
patch 8.0.1553: cannot see what digraph is used to insert a character
Christian Brabandt <cb@256bit.org>
parents:
13302
diff
changeset
|
145 c, c, c); |
714 | 146 if (ci == MAX_MCO) |
147 break; | |
963 | 148 if (enc_utf8) |
149 c = cc[ci++]; | |
150 else | |
151 c = 0; | |
7 | 152 } |
153 #endif | |
154 | |
155 msg(IObuff); | |
156 } | |
157 | |
158 /* | |
159 * ":left", ":center" and ":right": align text. | |
160 */ | |
161 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
162 ex_align(exarg_T *eap) |
7 | 163 { |
164 pos_T save_curpos; | |
165 int len; | |
166 int indent = 0; | |
167 int new_indent; | |
168 int has_tab; | |
169 int width; | |
170 | |
171 #ifdef FEAT_RIGHTLEFT | |
172 if (curwin->w_p_rl) | |
173 { | |
174 /* switch left and right aligning */ | |
175 if (eap->cmdidx == CMD_right) | |
176 eap->cmdidx = CMD_left; | |
177 else if (eap->cmdidx == CMD_left) | |
178 eap->cmdidx = CMD_right; | |
179 } | |
180 #endif | |
181 | |
182 width = atoi((char *)eap->arg); | |
183 save_curpos = curwin->w_cursor; | |
184 if (eap->cmdidx == CMD_left) /* width is used for new indent */ | |
185 { | |
186 if (width >= 0) | |
187 indent = width; | |
188 } | |
189 else | |
190 { | |
191 /* | |
192 * if 'textwidth' set, use it | |
193 * else if 'wrapmargin' set, use it | |
194 * if invalid value, use 80 | |
195 */ | |
196 if (width <= 0) | |
197 width = curbuf->b_p_tw; | |
198 if (width == 0 && curbuf->b_p_wm > 0) | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
199 width = curwin->w_width - curbuf->b_p_wm; |
7 | 200 if (width <= 0) |
201 width = 80; | |
202 } | |
203 | |
204 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) | |
205 return; | |
206 | |
207 for (curwin->w_cursor.lnum = eap->line1; | |
208 curwin->w_cursor.lnum <= eap->line2; ++curwin->w_cursor.lnum) | |
209 { | |
210 if (eap->cmdidx == CMD_left) /* left align */ | |
211 new_indent = indent; | |
212 else | |
213 { | |
944 | 214 has_tab = FALSE; /* avoid uninit warnings */ |
7 | 215 len = linelen(eap->cmdidx == CMD_right ? &has_tab |
216 : NULL) - get_indent(); | |
217 | |
218 if (len <= 0) /* skip blank lines */ | |
219 continue; | |
220 | |
221 if (eap->cmdidx == CMD_center) | |
222 new_indent = (width - len) / 2; | |
223 else | |
224 { | |
225 new_indent = width - len; /* right align */ | |
226 | |
227 /* | |
228 * Make sure that embedded TABs don't make the text go too far | |
229 * to the right. | |
230 */ | |
231 if (has_tab) | |
232 while (new_indent > 0) | |
233 { | |
234 (void)set_indent(new_indent, 0); | |
235 if (linelen(NULL) <= width) | |
236 { | |
237 /* | |
238 * Now try to move the line as much as possible to | |
239 * the right. Stop when it moves too far. | |
240 */ | |
241 do | |
242 (void)set_indent(++new_indent, 0); | |
243 while (linelen(NULL) <= width); | |
244 --new_indent; | |
245 break; | |
246 } | |
247 --new_indent; | |
248 } | |
249 } | |
250 } | |
251 if (new_indent < 0) | |
252 new_indent = 0; | |
253 (void)set_indent(new_indent, 0); /* set indent */ | |
254 } | |
255 changed_lines(eap->line1, 0, eap->line2 + 1, 0L); | |
256 curwin->w_cursor = save_curpos; | |
257 beginline(BL_WHITE | BL_FIX); | |
258 } | |
259 | |
260 /* | |
261 * Get the length of the current line, excluding trailing white space. | |
262 */ | |
263 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
264 linelen(int *has_tab) |
7 | 265 { |
266 char_u *line; | |
267 char_u *first; | |
268 char_u *last; | |
269 int save; | |
270 int len; | |
271 | |
272 /* find the first non-blank character */ | |
273 line = ml_get_curline(); | |
274 first = skipwhite(line); | |
275 | |
276 /* find the character after the last non-blank character */ | |
277 for (last = first + STRLEN(first); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
278 last > first && VIM_ISWHITE(last[-1]); --last) |
7 | 279 ; |
280 save = *last; | |
281 *last = NUL; | |
282 len = linetabsize(line); /* get line length */ | |
283 if (has_tab != NULL) /* check for embedded TAB */ | |
284 *has_tab = (vim_strrchr(first, TAB) != NULL); | |
285 *last = save; | |
286 | |
287 return len; | |
288 } | |
289 | |
826 | 290 /* Buffer for two lines used during sorting. They are allocated to |
291 * contain the longest line being sorted. */ | |
292 static char_u *sortbuf1; | |
293 static char_u *sortbuf2; | |
284 | 294 |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
295 static int sort_ic; /* ignore case */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
296 static int sort_nr; /* sort on number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
297 static int sort_rx; /* sort on regex instead of skipping it */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
298 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
299 static int sort_flt; /* sort on floating number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
300 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
301 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
302 static int sort_abort; /* flag to indicate if sorting has been interrupted */ |
294 | 303 |
304 /* Struct to store info to be sorted. */ | |
305 typedef struct | |
306 { | |
307 linenr_T lnum; /* line number */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
308 union { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
309 struct |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
310 { |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
311 varnumber_T start_col_nr; /* starting column number */ |
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
312 varnumber_T end_col_nr; /* ending column number */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
313 } line; |
9389
32e34e574716
commit https://github.com/vim/vim/commit/22fcfad29276bd5f317faf516637dcd491b96a12
Christian Brabandt <cb@256bit.org>
parents:
9387
diff
changeset
|
314 varnumber_T value; /* value if sorting by integer */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
315 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
316 float_T value_flt; /* value if sorting by float */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
317 #endif |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
318 } st_u; |
294 | 319 } sorti_T; |
284 | 320 |
321 static int | |
322 #ifdef __BORLANDC__ | |
323 _RTLENTRYF | |
324 #endif | |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
325 sort_compare(const void *s1, const void *s2); |
284 | 326 |
327 static int | |
328 #ifdef __BORLANDC__ | |
329 _RTLENTRYF | |
330 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
331 sort_compare(const void *s1, const void *s2) |
284 | 332 { |
294 | 333 sorti_T l1 = *(sorti_T *)s1; |
334 sorti_T l2 = *(sorti_T *)s2; | |
826 | 335 int result = 0; |
336 | |
337 /* If the user interrupts, there's no way to stop qsort() immediately, but | |
834 | 338 * if we return 0 every time, qsort will assume it's done sorting and |
339 * exit. */ | |
826 | 340 if (sort_abort) |
341 return 0; | |
342 fast_breakcheck(); | |
343 if (got_int) | |
344 sort_abort = TRUE; | |
345 | |
834 | 346 /* When sorting numbers "start_col_nr" is the number, not the column |
347 * number. */ | |
294 | 348 if (sort_nr) |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
349 result = l1.st_u.value == l2.st_u.value ? 0 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
350 : l1.st_u.value > l2.st_u.value ? 1 : -1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
351 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
352 else if (sort_flt) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
353 result = l1.st_u.value_flt == l2.st_u.value_flt ? 0 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
354 : l1.st_u.value_flt > l2.st_u.value_flt ? 1 : -1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
355 #endif |
826 | 356 else |
357 { | |
834 | 358 /* We need to copy one line into "sortbuf1", because there is no |
359 * guarantee that the first pointer becomes invalid when obtaining the | |
360 * second one. */ | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
361 STRNCPY(sortbuf1, ml_get(l1.lnum) + l1.st_u.line.start_col_nr, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
362 l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
363 sortbuf1[l1.st_u.line.end_col_nr - l1.st_u.line.start_col_nr] = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
364 STRNCPY(sortbuf2, ml_get(l2.lnum) + l2.st_u.line.start_col_nr, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
365 l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
366 sortbuf2[l2.st_u.line.end_col_nr - l2.st_u.line.start_col_nr] = 0; |
826 | 367 |
834 | 368 result = sort_ic ? STRICMP(sortbuf1, sortbuf2) |
369 : STRCMP(sortbuf1, sortbuf2); | |
370 } | |
371 | |
372 /* If two lines have the same value, preserve the original line order. */ | |
826 | 373 if (result == 0) |
834 | 374 return (int)(l1.lnum - l2.lnum); |
375 return result; | |
284 | 376 } |
377 | |
378 /* | |
379 * ":sort". | |
380 */ | |
381 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
382 ex_sort(exarg_T *eap) |
284 | 383 { |
384 regmatch_T regmatch; | |
385 int len; | |
386 linenr_T lnum; | |
387 long maxlen = 0; | |
294 | 388 sorti_T *nrs; |
1872 | 389 size_t count = (size_t)(eap->line2 - eap->line1 + 1); |
294 | 390 size_t i; |
284 | 391 char_u *p; |
392 char_u *s; | |
826 | 393 char_u *s2; |
394 char_u c; /* temporary character storage */ | |
284 | 395 int unique = FALSE; |
396 long deleted; | |
826 | 397 colnr_T start_col; |
398 colnr_T end_col; | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
399 int sort_what = 0; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
400 int format_found = 0; |
284 | 401 |
1538 | 402 /* Sorting one line is really quick! */ |
403 if (count <= 1) | |
404 return; | |
405 | |
284 | 406 if (u_save((linenr_T)(eap->line1 - 1), (linenr_T)(eap->line2 + 1)) == FAIL) |
407 return; | |
826 | 408 sortbuf1 = NULL; |
409 sortbuf2 = NULL; | |
284 | 410 regmatch.regprog = NULL; |
294 | 411 nrs = (sorti_T *)lalloc((long_u)(count * sizeof(sorti_T)), TRUE); |
284 | 412 if (nrs == NULL) |
826 | 413 goto sortend; |
414 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
415 sort_abort = sort_ic = sort_rx = sort_nr = 0; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
416 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
417 sort_flt = 0; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
418 #endif |
294 | 419 |
284 | 420 for (p = eap->arg; *p != NUL; ++p) |
421 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
422 if (VIM_ISWHITE(*p)) |
284 | 423 ; |
424 else if (*p == 'i') | |
425 sort_ic = TRUE; | |
826 | 426 else if (*p == 'r') |
427 sort_rx = TRUE; | |
294 | 428 else if (*p == 'n') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
429 { |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
430 sort_nr = 1; |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
431 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
432 } |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
433 #ifdef FEAT_FLOAT |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
434 else if (*p == 'f') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
435 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
436 sort_flt = 1; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
437 ++format_found; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
438 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
439 #endif |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
440 else if (*p == 'b') |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
441 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
442 sort_what = STR2NR_BIN + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
443 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
444 } |
294 | 445 else if (*p == 'o') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
446 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
447 sort_what = STR2NR_OCT + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
448 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
449 } |
294 | 450 else if (*p == 'x') |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
451 { |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
452 sort_what = STR2NR_HEX + STR2NR_FORCE; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
453 ++format_found; |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
454 } |
284 | 455 else if (*p == 'u') |
456 unique = TRUE; | |
289 | 457 else if (*p == '"') /* comment start */ |
458 break; | |
459 else if (check_nextcmd(p) != NULL) | |
460 { | |
461 eap->nextcmd = check_nextcmd(p); | |
462 break; | |
463 } | |
464 else if (!ASCII_ISALPHA(*p) && regmatch.regprog == NULL) | |
284 | 465 { |
466 s = skip_regexp(p + 1, *p, TRUE, NULL); | |
467 if (*s != *p) | |
468 { | |
469 EMSG(_(e_invalpat)); | |
826 | 470 goto sortend; |
284 | 471 } |
472 *s = NUL; | |
1314 | 473 /* Use last search pattern if sort pattern is empty. */ |
4199 | 474 if (s == p + 1) |
475 { | |
476 if (last_search_pat() == NULL) | |
477 { | |
478 EMSG(_(e_noprevre)); | |
479 goto sortend; | |
480 } | |
1314 | 481 regmatch.regprog = vim_regcomp(last_search_pat(), RE_MAGIC); |
4199 | 482 } |
1314 | 483 else |
484 regmatch.regprog = vim_regcomp(p + 1, RE_MAGIC); | |
284 | 485 if (regmatch.regprog == NULL) |
826 | 486 goto sortend; |
289 | 487 p = s; /* continue after the regexp */ |
284 | 488 regmatch.rm_ic = p_ic; |
489 } | |
490 else | |
491 { | |
492 EMSG2(_(e_invarg2), p); | |
826 | 493 goto sortend; |
284 | 494 } |
495 } | |
496 | |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
497 /* Can only have one of 'n', 'b', 'o' and 'x'. */ |
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
498 if (format_found > 1) |
294 | 499 { |
500 EMSG(_(e_invarg)); | |
826 | 501 goto sortend; |
294 | 502 } |
503 | |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
504 /* From here on "sort_nr" is used as a flag for any integer number |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
505 * sorting. */ |
7447
ad432f8f68fb
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Christian Brabandt <cb@256bit.org>
parents:
7412
diff
changeset
|
506 sort_nr += sort_what; |
294 | 507 |
284 | 508 /* |
294 | 509 * Make an array with all line numbers. This avoids having to copy all |
284 | 510 * the lines into allocated memory. |
826 | 511 * When sorting on strings "start_col_nr" is the offset in the line, for |
512 * numbers sorting it's the number to sort on. This means the pattern | |
513 * matching and number conversion only has to be done once per line. | |
294 | 514 * Also get the longest line length for allocating "sortbuf". |
284 | 515 */ |
516 for (lnum = eap->line1; lnum <= eap->line2; ++lnum) | |
517 { | |
518 s = ml_get(lnum); | |
835 | 519 len = (int)STRLEN(s); |
284 | 520 if (maxlen < len) |
521 maxlen = len; | |
294 | 522 |
826 | 523 start_col = 0; |
524 end_col = len; | |
294 | 525 if (regmatch.regprog != NULL && vim_regexec(®match, s, 0)) |
826 | 526 { |
527 if (sort_rx) | |
528 { | |
835 | 529 start_col = (colnr_T)(regmatch.startp[0] - s); |
530 end_col = (colnr_T)(regmatch.endp[0] - s); | |
826 | 531 } |
532 else | |
835 | 533 start_col = (colnr_T)(regmatch.endp[0] - s); |
826 | 534 } |
294 | 535 else |
826 | 536 if (regmatch.regprog != NULL) |
537 end_col = 0; | |
294 | 538 |
7844
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
539 if (sort_nr |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
540 #ifdef FEAT_FLOAT |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
541 || sort_flt |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
542 #endif |
6669966db9e9
commit https://github.com/vim/vim/commit/937204a9175d0fe2f13c8bc4ebeb043003d7e7d7
Christian Brabandt <cb@256bit.org>
parents:
7819
diff
changeset
|
543 ) |
294 | 544 { |
826 | 545 /* Make sure vim_str2nr doesn't read any digits past the end |
546 * of the match, by temporarily terminating the string there */ | |
547 s2 = s + end_col; | |
548 c = *s2; | |
2606 | 549 *s2 = NUL; |
294 | 550 /* Sorting on number: Store the number itself. */ |
1687 | 551 p = s + start_col; |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
552 if (sort_nr) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
553 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
554 if (sort_what & STR2NR_HEX) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
555 s = skiptohex(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
556 else if (sort_what & STR2NR_BIN) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
557 s = skiptobin(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
558 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
559 s = skiptodigit(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
560 if (s > p && s[-1] == '-') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
561 --s; /* include preceding negative sign */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
562 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
563 /* empty line should sort before any number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
564 nrs[lnum - eap->line1].st_u.value = -MAXLNUM; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
565 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
566 vim_str2nr(s, NULL, NULL, sort_what, |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
567 &nrs[lnum - eap->line1].st_u.value, NULL, 0); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
568 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
569 #ifdef FEAT_FLOAT |
294 | 570 else |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
571 { |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
572 s = skipwhite(p); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
573 if (*s == '+') |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
574 s = skipwhite(s + 1); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
575 |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
576 if (*s == NUL) |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
577 /* empty line should sort before any number */ |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
578 nrs[lnum - eap->line1].st_u.value_flt = -DBL_MAX; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
579 else |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
580 nrs[lnum - eap->line1].st_u.value_flt = |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
581 strtod((char *)s, NULL); |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
582 } |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
583 #endif |
2606 | 584 *s2 = c; |
294 | 585 } |
586 else | |
826 | 587 { |
294 | 588 /* Store the column to sort at. */ |
7689
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
589 nrs[lnum - eap->line1].st_u.line.start_col_nr = start_col; |
20dc2763a3b9
commit https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Christian Brabandt <cb@256bit.org>
parents:
7664
diff
changeset
|
590 nrs[lnum - eap->line1].st_u.line.end_col_nr = end_col; |
826 | 591 } |
294 | 592 |
593 nrs[lnum - eap->line1].lnum = lnum; | |
481 | 594 |
595 if (regmatch.regprog != NULL) | |
596 fast_breakcheck(); | |
597 if (got_int) | |
826 | 598 goto sortend; |
284 | 599 } |
600 | |
294 | 601 /* Allocate a buffer that can hold the longest line. */ |
826 | 602 sortbuf1 = alloc((unsigned)maxlen + 1); |
603 if (sortbuf1 == NULL) | |
604 goto sortend; | |
605 sortbuf2 = alloc((unsigned)maxlen + 1); | |
606 if (sortbuf2 == NULL) | |
607 goto sortend; | |
284 | 608 |
481 | 609 /* Sort the array of line numbers. Note: can't be interrupted! */ |
294 | 610 qsort((void *)nrs, count, sizeof(sorti_T), sort_compare); |
284 | 611 |
826 | 612 if (sort_abort) |
613 goto sortend; | |
614 | |
284 | 615 /* Insert the lines in the sorted order below the last one. */ |
616 lnum = eap->line2; | |
617 for (i = 0; i < count; ++i) | |
618 { | |
619 s = ml_get(nrs[eap->forceit ? count - i - 1 : i].lnum); | |
620 if (!unique || i == 0 | |
826 | 621 || (sort_ic ? STRICMP(s, sortbuf1) : STRCMP(s, sortbuf1)) != 0) |
284 | 622 { |
7340
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
623 /* Copy the line into a buffer, it may become invalid in |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
624 * ml_append(). And it's needed for "unique". */ |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
625 STRCPY(sortbuf1, s); |
645abb8d8daf
commit https://github.com/vim/vim/commit/75e3ad019933f4879137775549261bf51985ab7d
Christian Brabandt <cb@256bit.org>
parents:
7226
diff
changeset
|
626 if (ml_append(lnum++, sortbuf1, (colnr_T)0, FALSE) == FAIL) |
284 | 627 break; |
628 } | |
481 | 629 fast_breakcheck(); |
630 if (got_int) | |
826 | 631 goto sortend; |
284 | 632 } |
633 | |
634 /* delete the original lines if appending worked */ | |
635 if (i == count) | |
636 for (i = 0; i < count; ++i) | |
637 ml_delete(eap->line1, FALSE); | |
638 else | |
639 count = 0; | |
640 | |
294 | 641 /* Adjust marks for deleted (or added) lines and prepare for displaying. */ |
835 | 642 deleted = (long)(count - (lnum - eap->line2)); |
284 | 643 if (deleted > 0) |
644 mark_adjust(eap->line2 - deleted, eap->line2, (long)MAXLNUM, -deleted); | |
645 else if (deleted < 0) | |
646 mark_adjust(eap->line2, MAXLNUM, -deleted, 0L); | |
647 changed_lines(eap->line1, 0, eap->line2 + 1, -deleted); | |
294 | 648 |
284 | 649 curwin->w_cursor.lnum = eap->line1; |
650 beginline(BL_WHITE | BL_FIX); | |
651 | |
826 | 652 sortend: |
284 | 653 vim_free(nrs); |
826 | 654 vim_free(sortbuf1); |
655 vim_free(sortbuf2); | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
656 vim_regfree(regmatch.regprog); |
481 | 657 if (got_int) |
658 EMSG(_(e_interr)); | |
284 | 659 } |
660 | |
7 | 661 /* |
662 * ":retab". | |
663 */ | |
664 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
665 ex_retab(exarg_T *eap) |
7 | 666 { |
667 linenr_T lnum; | |
668 int got_tab = FALSE; | |
669 long num_spaces = 0; | |
670 long num_tabs; | |
671 long len; | |
672 long col; | |
673 long vcol; | |
674 long start_col = 0; /* For start of white-space string */ | |
675 long start_vcol = 0; /* For start of white-space string */ | |
676 long old_len; | |
677 char_u *ptr; | |
678 char_u *new_line = (char_u *)1; /* init to non-NULL */ | |
679 int did_undo; /* called u_save for current line */ | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
680 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
681 int *new_ts = 0; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
682 char_u *new_ts_str; /* string value of tab argument */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
683 #else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
684 int temp; |
7 | 685 int new_ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
686 #endif |
7 | 687 int save_list; |
688 linenr_T first_line = 0; /* first changed line */ | |
689 linenr_T last_line = 0; /* last changed line */ | |
690 | |
691 save_list = curwin->w_p_list; | |
692 curwin->w_p_list = 0; /* don't want list mode here */ | |
693 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
694 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
695 new_ts_str = eap->arg; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
696 if (!tabstop_set(eap->arg, &new_ts)) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
697 return; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
698 while (vim_isdigit(*(eap->arg)) || *(eap->arg) == ',') |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
699 ++(eap->arg); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
700 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
701 // This ensures that either new_ts and new_ts_str are freshly allocated, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
702 // or new_ts points to an existing array and new_ts_str is null. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
703 if (new_ts == 0) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
704 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
705 new_ts = curbuf->b_p_vts_array; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
706 new_ts_str = NULL; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
707 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
708 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
709 new_ts_str = vim_strnsave(new_ts_str, eap->arg - new_ts_str); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
710 #else |
7 | 711 new_ts = getdigits(&(eap->arg)); |
712 if (new_ts < 0) | |
713 { | |
714 EMSG(_(e_positive)); | |
715 return; | |
716 } | |
717 if (new_ts == 0) | |
718 new_ts = curbuf->b_p_ts; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
719 #endif |
7 | 720 for (lnum = eap->line1; !got_int && lnum <= eap->line2; ++lnum) |
721 { | |
722 ptr = ml_get(lnum); | |
723 col = 0; | |
724 vcol = 0; | |
725 did_undo = FALSE; | |
726 for (;;) | |
727 { | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
728 if (VIM_ISWHITE(ptr[col])) |
7 | 729 { |
730 if (!got_tab && num_spaces == 0) | |
731 { | |
732 /* First consecutive white-space */ | |
733 start_vcol = vcol; | |
734 start_col = col; | |
735 } | |
736 if (ptr[col] == ' ') | |
737 num_spaces++; | |
738 else | |
739 got_tab = TRUE; | |
740 } | |
741 else | |
742 { | |
743 if (got_tab || (eap->forceit && num_spaces > 1)) | |
744 { | |
745 /* Retabulate this string of white-space */ | |
746 | |
747 /* len is virtual length of white string */ | |
748 len = num_spaces = vcol - start_vcol; | |
749 num_tabs = 0; | |
750 if (!curbuf->b_p_et) | |
751 { | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
752 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
753 int t, s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
754 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
755 tabstop_fromto(start_vcol, vcol, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
756 tabstop_count(new_ts)? 0: curbuf->b_p_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
757 new_ts, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
758 &t, &s); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
759 num_tabs = t; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
760 num_spaces = s; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
761 #else |
7 | 762 temp = new_ts - (start_vcol % new_ts); |
763 if (num_spaces >= temp) | |
764 { | |
765 num_spaces -= temp; | |
766 num_tabs++; | |
767 } | |
768 num_tabs += num_spaces / new_ts; | |
769 num_spaces -= (num_spaces / new_ts) * new_ts; | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
770 #endif |
7 | 771 } |
772 if (curbuf->b_p_et || got_tab || | |
773 (num_spaces + num_tabs < len)) | |
774 { | |
775 if (did_undo == FALSE) | |
776 { | |
777 did_undo = TRUE; | |
778 if (u_save((linenr_T)(lnum - 1), | |
779 (linenr_T)(lnum + 1)) == FAIL) | |
780 { | |
781 new_line = NULL; /* flag out-of-memory */ | |
782 break; | |
783 } | |
784 } | |
785 | |
786 /* len is actual number of white characters used */ | |
787 len = num_spaces + num_tabs; | |
788 old_len = (long)STRLEN(ptr); | |
789 new_line = lalloc(old_len - col + start_col + len + 1, | |
790 TRUE); | |
791 if (new_line == NULL) | |
792 break; | |
793 if (start_col > 0) | |
794 mch_memmove(new_line, ptr, (size_t)start_col); | |
795 mch_memmove(new_line + start_col + len, | |
796 ptr + col, (size_t)(old_len - col + 1)); | |
797 ptr = new_line + start_col; | |
798 for (col = 0; col < len; col++) | |
799 ptr[col] = (col < num_tabs) ? '\t' : ' '; | |
800 ml_replace(lnum, new_line, FALSE); | |
801 if (first_line == 0) | |
802 first_line = lnum; | |
803 last_line = lnum; | |
804 ptr = new_line; | |
805 col = start_col + len; | |
806 } | |
807 } | |
808 got_tab = FALSE; | |
809 num_spaces = 0; | |
810 } | |
811 if (ptr[col] == NUL) | |
812 break; | |
813 vcol += chartabsize(ptr + col, (colnr_T)vcol); | |
814 #ifdef FEAT_MBYTE | |
815 if (has_mbyte) | |
474 | 816 col += (*mb_ptr2len)(ptr + col); |
7 | 817 else |
818 #endif | |
819 ++col; | |
820 } | |
821 if (new_line == NULL) /* out of memory */ | |
822 break; | |
823 line_breakcheck(); | |
824 } | |
825 if (got_int) | |
826 EMSG(_(e_interr)); | |
827 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
828 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
829 // If a single value was given then it can be considered equal to |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
830 // either the value of 'tabstop' or the value of 'vartabstop'. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
831 if (tabstop_count(curbuf->b_p_vts_array) == 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
832 && tabstop_count(new_ts) == 1 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
833 && curbuf->b_p_ts == tabstop_first(new_ts)) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
834 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
835 else if (tabstop_count(curbuf->b_p_vts_array) > 0 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
836 && tabstop_eq(curbuf->b_p_vts_array, new_ts)) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
837 ; /* not changed */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
838 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
839 redraw_curbuf_later(NOT_VALID); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
840 #else |
7 | 841 if (curbuf->b_p_ts != new_ts) |
842 redraw_curbuf_later(NOT_VALID); | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
843 #endif |
7 | 844 if (first_line != 0) |
845 changed_lines(first_line, 0, last_line + 1, 0L); | |
846 | |
847 curwin->w_p_list = save_list; /* restore 'list' */ | |
848 | |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
849 #ifdef FEAT_VARTABS |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
850 if (new_ts_str != NULL) /* set the new tabstop */ |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
851 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
852 // If 'vartabstop' is in use or if the value given to retab has more |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
853 // than one tabstop then update 'vartabstop'. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
854 int *old_vts_ary = curbuf->b_p_vts_array; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
855 |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
856 if (tabstop_count(old_vts_ary) > 0 || tabstop_count(new_ts) > 1) |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
857 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
858 set_string_option_direct((char_u *)"vts", -1, new_ts_str, |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
859 OPT_FREE|OPT_LOCAL, 0); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
860 vim_free(new_ts_str); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
861 curbuf->b_p_vts_array = new_ts; |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
862 vim_free(old_vts_ary); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
863 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
864 else |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
865 { |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
866 // 'vartabstop' wasn't in use and a single value was given to |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
867 // retab then update 'tabstop'. |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
868 curbuf->b_p_ts = tabstop_first(new_ts); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
869 vim_free(new_ts); |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
870 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
871 } |
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
872 #else |
7 | 873 curbuf->b_p_ts = new_ts; |
14175
2ad722003b36
patch 8.1.0105: all tab stops are the same
Christian Brabandt <cb@256bit.org>
parents:
14033
diff
changeset
|
874 #endif |
7 | 875 coladvance(curwin->w_curswant); |
876 | |
877 u_clearline(); | |
878 } | |
879 | |
880 /* | |
881 * :move command - move lines line1-line2 to line dest | |
882 * | |
883 * return FAIL for failure, OK otherwise | |
884 */ | |
885 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
886 do_move(linenr_T line1, linenr_T line2, linenr_T dest) |
7 | 887 { |
888 char_u *str; | |
889 linenr_T l; | |
890 linenr_T extra; /* Num lines added before line1 */ | |
891 linenr_T num_lines; /* Num lines moved */ | |
892 linenr_T last_line; /* Last line in file after adding new text */ | |
6755 | 893 #ifdef FEAT_FOLDING |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
894 win_T *win; |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
895 tabpage_T *tp; |
6755 | 896 #endif |
7 | 897 |
898 if (dest >= line1 && dest < line2) | |
899 { | |
900 EMSG(_("E134: Move lines into themselves")); | |
901 return FAIL; | |
902 } | |
903 | |
904 num_lines = line2 - line1 + 1; | |
905 | |
906 /* | |
907 * First we copy the old text to its new location -- webb | |
908 * Also copy the flag that ":global" command uses. | |
909 */ | |
910 if (u_save(dest, dest + 1) == FAIL) | |
911 return FAIL; | |
912 for (extra = 0, l = line1; l <= line2; l++) | |
913 { | |
914 str = vim_strsave(ml_get(l + extra)); | |
915 if (str != NULL) | |
916 { | |
917 ml_append(dest + l - line1, str, (colnr_T)0, FALSE); | |
918 vim_free(str); | |
919 if (dest < line1) | |
920 extra++; | |
921 } | |
922 } | |
923 | |
924 /* | |
925 * Now we must be careful adjusting our marks so that we don't overlap our | |
926 * mark_adjust() calls. | |
927 * | |
928 * We adjust the marks within the old text so that they refer to the | |
929 * last lines of the file (temporarily), because we know no other marks | |
930 * will be set there since these line numbers did not exist until we added | |
931 * our new lines. | |
932 * | |
933 * Then we adjust the marks on lines between the old and new text positions | |
934 * (either forwards or backwards). | |
935 * | |
936 * And Finally we adjust the marks we put at the end of the file back to | |
937 * their final destination at the new text position -- webb | |
938 */ | |
939 last_line = curbuf->b_ml.ml_line_count; | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
940 mark_adjust_nofold(line1, line2, last_line - line2, 0L); |
7 | 941 if (dest >= line2) |
942 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
943 mark_adjust_nofold(line2 + 1, dest, -num_lines, 0L); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
944 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
945 FOR_ALL_TAB_WINDOWS(tp, win) { |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
946 if (win->w_buffer == curbuf) |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
947 foldMoveRange(&win->w_folds, line1, line2, dest); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
948 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
949 #endif |
7 | 950 curbuf->b_op_start.lnum = dest - num_lines + 1; |
951 curbuf->b_op_end.lnum = dest; | |
952 } | |
953 else | |
954 { | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
955 mark_adjust_nofold(dest + 1, line1 - 1, num_lines, 0L); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
956 #ifdef FEAT_FOLDING |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
957 FOR_ALL_TAB_WINDOWS(tp, win) { |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
958 if (win->w_buffer == curbuf) |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
959 foldMoveRange(&win->w_folds, dest + 1, line1 - 1, line2); |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
960 } |
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
961 #endif |
7 | 962 curbuf->b_op_start.lnum = dest + 1; |
963 curbuf->b_op_end.lnum = dest + num_lines; | |
964 } | |
965 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
11140
6b26e044b6f5
patch 8.0.0457: using :move messes up manual folds
Christian Brabandt <cb@256bit.org>
parents:
11129
diff
changeset
|
966 mark_adjust_nofold(last_line - num_lines + 1, last_line, |
7 | 967 -(last_line - dest - extra), 0L); |
968 | |
969 /* | |
970 * Now we delete the original text -- webb | |
971 */ | |
972 if (u_save(line1 + extra - 1, line2 + extra + 1) == FAIL) | |
973 return FAIL; | |
974 | |
975 for (l = line1; l <= line2; l++) | |
976 ml_delete(line1 + extra, TRUE); | |
977 | |
978 if (!global_busy && num_lines > p_report) | |
979 { | |
980 if (num_lines == 1) | |
981 MSG(_("1 line moved")); | |
982 else | |
983 smsg((char_u *)_("%ld lines moved"), num_lines); | |
984 } | |
985 | |
986 /* | |
987 * Leave the cursor on the last of the moved lines. | |
988 */ | |
989 if (dest >= line1) | |
990 curwin->w_cursor.lnum = dest; | |
991 else | |
992 curwin->w_cursor.lnum = dest + (line2 - line1) + 1; | |
993 | |
994 if (line1 < dest) | |
3184 | 995 { |
996 dest += num_lines + 1; | |
997 last_line = curbuf->b_ml.ml_line_count; | |
998 if (dest > last_line + 1) | |
999 dest = last_line + 1; | |
1000 changed_lines(line1, 0, dest, 0L); | |
1001 } | |
7 | 1002 else |
1003 changed_lines(dest + 1, 0, line1 + num_lines, 0L); | |
1004 | |
1005 return OK; | |
1006 } | |
1007 | |
1008 /* | |
1009 * ":copy" | |
1010 */ | |
1011 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1012 ex_copy(linenr_T line1, linenr_T line2, linenr_T n) |
7 | 1013 { |
1014 linenr_T count; | |
1015 char_u *p; | |
1016 | |
1017 count = line2 - line1 + 1; | |
1018 curbuf->b_op_start.lnum = n + 1; | |
1019 curbuf->b_op_end.lnum = n + count; | |
1020 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
1021 | |
1022 /* | |
1023 * there are three situations: | |
1024 * 1. destination is above line1 | |
1025 * 2. destination is between line1 and line2 | |
1026 * 3. destination is below line2 | |
1027 * | |
1028 * n = destination (when starting) | |
1029 * curwin->w_cursor.lnum = destination (while copying) | |
1030 * line1 = start of source (while copying) | |
1031 * line2 = end of source (while copying) | |
1032 */ | |
1033 if (u_save(n, n + 1) == FAIL) | |
1034 return; | |
1035 | |
1036 curwin->w_cursor.lnum = n; | |
1037 while (line1 <= line2) | |
1038 { | |
1039 /* need to use vim_strsave() because the line will be unlocked within | |
1040 * ml_append() */ | |
1041 p = vim_strsave(ml_get(line1)); | |
1042 if (p != NULL) | |
1043 { | |
1044 ml_append(curwin->w_cursor.lnum, p, (colnr_T)0, FALSE); | |
1045 vim_free(p); | |
1046 } | |
1047 /* situation 2: skip already copied lines */ | |
1048 if (line1 == n) | |
1049 line1 = curwin->w_cursor.lnum; | |
1050 ++line1; | |
1051 if (curwin->w_cursor.lnum < line1) | |
1052 ++line1; | |
1053 if (curwin->w_cursor.lnum < line2) | |
1054 ++line2; | |
1055 ++curwin->w_cursor.lnum; | |
1056 } | |
1057 | |
1058 appended_lines_mark(n, count); | |
1059 | |
1060 msgmore((long)count); | |
1061 } | |
1062 | |
359 | 1063 static char_u *prevcmd = NULL; /* the previous command */ |
1064 | |
1065 #if defined(EXITFREE) || defined(PROTO) | |
1066 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1067 free_prev_shellcmd(void) |
359 | 1068 { |
1069 vim_free(prevcmd); | |
1070 } | |
1071 #endif | |
1072 | |
7 | 1073 /* |
1074 * Handle the ":!cmd" command. Also for ":r !cmd" and ":w !cmd" | |
1075 * Bangs in the argument are replaced with the previously entered command. | |
1076 * Remember the argument. | |
1077 */ | |
1078 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1079 do_bang( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1080 int addr_count, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1081 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1082 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1083 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1084 int do_out) |
7 | 1085 { |
1086 char_u *arg = eap->arg; /* command */ | |
1087 linenr_T line1 = eap->line1; /* start of range */ | |
1088 linenr_T line2 = eap->line2; /* end of range */ | |
1089 char_u *newcmd = NULL; /* the new command */ | |
1090 int free_newcmd = FALSE; /* need to free() newcmd */ | |
1091 int ins_prevcmd; | |
1092 char_u *t; | |
1093 char_u *p; | |
1094 char_u *trailarg; | |
1095 int len; | |
1096 int scroll_save = msg_scroll; | |
1097 | |
1098 /* | |
1099 * Disallow shell commands for "rvim". | |
1100 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1101 * security reasons. | |
1102 */ | |
1103 if (check_restricted() || check_secure()) | |
1104 return; | |
1105 | |
1106 if (addr_count == 0) /* :! */ | |
1107 { | |
1108 msg_scroll = FALSE; /* don't scroll here */ | |
1109 autowrite_all(); | |
1110 msg_scroll = scroll_save; | |
1111 } | |
1112 | |
1113 /* | |
1114 * Try to find an embedded bang, like in :!<cmd> ! [args] | |
1115 * (:!! is indicated by the 'forceit' variable) | |
1116 */ | |
1117 ins_prevcmd = forceit; | |
1118 trailarg = arg; | |
1119 do | |
1120 { | |
1121 len = (int)STRLEN(trailarg) + 1; | |
1122 if (newcmd != NULL) | |
1123 len += (int)STRLEN(newcmd); | |
1124 if (ins_prevcmd) | |
1125 { | |
1126 if (prevcmd == NULL) | |
1127 { | |
1128 EMSG(_(e_noprev)); | |
1129 vim_free(newcmd); | |
1130 return; | |
1131 } | |
1132 len += (int)STRLEN(prevcmd); | |
1133 } | |
1872 | 1134 if ((t = alloc((unsigned)len)) == NULL) |
7 | 1135 { |
1136 vim_free(newcmd); | |
1137 return; | |
1138 } | |
1139 *t = NUL; | |
1140 if (newcmd != NULL) | |
1141 STRCAT(t, newcmd); | |
1142 if (ins_prevcmd) | |
1143 STRCAT(t, prevcmd); | |
1144 p = t + STRLEN(t); | |
1145 STRCAT(t, trailarg); | |
1146 vim_free(newcmd); | |
1147 newcmd = t; | |
1148 | |
1149 /* | |
1150 * Scan the rest of the argument for '!', which is replaced by the | |
1151 * previous command. "\!" is replaced by "!" (this is vi compatible). | |
1152 */ | |
1153 trailarg = NULL; | |
1154 while (*p) | |
1155 { | |
2823 | 1156 if (*p == '!') |
7 | 1157 { |
1158 if (p > newcmd && p[-1] == '\\') | |
1624 | 1159 STRMOVE(p - 1, p); |
7 | 1160 else |
1161 { | |
1162 trailarg = p; | |
1163 *trailarg++ = NUL; | |
1164 ins_prevcmd = TRUE; | |
1165 break; | |
1166 } | |
1167 } | |
1168 ++p; | |
1169 } | |
1170 } while (trailarg != NULL); | |
1171 | |
1172 vim_free(prevcmd); | |
1173 prevcmd = newcmd; | |
1174 | |
1175 if (bangredo) /* put cmd in redo buffer for ! command */ | |
1176 { | |
5728 | 1177 /* If % or # appears in the command, it must have been escaped. |
1178 * Reescape them, so that redoing them does not substitute them by the | |
1179 * buffername. */ | |
1180 char_u *cmd = vim_strsave_escaped(prevcmd, (char_u *)"%#"); | |
1181 | |
1182 if (cmd != NULL) | |
1183 { | |
1184 AppendToRedobuffLit(cmd, -1); | |
1185 vim_free(cmd); | |
1186 } | |
1187 else | |
1188 AppendToRedobuffLit(prevcmd, -1); | |
7 | 1189 AppendToRedobuff((char_u *)"\n"); |
1190 bangredo = FALSE; | |
1191 } | |
1192 /* | |
1193 * Add quotes around the command, for shells that need them. | |
1194 */ | |
1195 if (*p_shq != NUL) | |
1196 { | |
1197 newcmd = alloc((unsigned)(STRLEN(prevcmd) + 2 * STRLEN(p_shq) + 1)); | |
1198 if (newcmd == NULL) | |
1199 return; | |
1200 STRCPY(newcmd, p_shq); | |
1201 STRCAT(newcmd, prevcmd); | |
1202 STRCAT(newcmd, p_shq); | |
1203 free_newcmd = TRUE; | |
1204 } | |
1205 if (addr_count == 0) /* :! */ | |
1206 { | |
1207 /* echo the command */ | |
1208 msg_start(); | |
1209 msg_putchar(':'); | |
1210 msg_putchar('!'); | |
1211 msg_outtrans(newcmd); | |
1212 msg_clr_eos(); | |
1213 windgoto(msg_row, msg_col); | |
1214 | |
1215 do_shell(newcmd, 0); | |
1216 } | |
1217 else /* :range! */ | |
725 | 1218 { |
7 | 1219 /* Careful: This may recursively call do_bang() again! (because of |
1220 * autocommands) */ | |
1221 do_filter(line1, line2, eap, newcmd, do_in, do_out); | |
725 | 1222 apply_autocmds(EVENT_SHELLFILTERPOST, NULL, NULL, FALSE, curbuf); |
1223 } | |
7 | 1224 if (free_newcmd) |
1225 vim_free(newcmd); | |
1226 } | |
1227 | |
1228 /* | |
1229 * do_filter: filter lines through a command given by the user | |
1230 * | |
169 | 1231 * We mostly use temp files and the call_shell() routine here. This would |
1232 * normally be done using pipes on a UNIX machine, but this is more portable | |
1233 * to non-unix machines. The call_shell() routine needs to be able | |
7 | 1234 * to deal with redirection somehow, and should handle things like looking |
1235 * at the PATH env. variable, and adding reasonable extensions to the | |
1236 * command name given by the user. All reasonable versions of call_shell() | |
1237 * do this. | |
169 | 1238 * Alternatively, if on Unix and redirecting input or output, but not both, |
1239 * and the 'shelltemp' option isn't set, use pipes. | |
7 | 1240 * We use input redirection if do_in is TRUE. |
1241 * We use output redirection if do_out is TRUE. | |
1242 */ | |
1243 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1244 do_filter( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1245 linenr_T line1, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1246 linenr_T line2, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1247 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
|
1248 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1249 int do_in, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1250 int do_out) |
7 | 1251 { |
1252 char_u *itmp = NULL; | |
1253 char_u *otmp = NULL; | |
1254 linenr_T linecount; | |
1255 linenr_T read_linecount; | |
1256 pos_T cursor_save; | |
1257 char_u *cmd_buf; | |
1258 buf_T *old_curbuf = curbuf; | |
169 | 1259 int shell_flags = 0; |
7 | 1260 |
1261 if (*cmd == NUL) /* no filter command */ | |
1262 return; | |
1263 | |
1264 cursor_save = curwin->w_cursor; | |
1265 linecount = line2 - line1 + 1; | |
1266 curwin->w_cursor.lnum = line1; | |
1267 curwin->w_cursor.col = 0; | |
1268 changed_line_abv_curs(); | |
1269 invalidate_botline(); | |
1270 | |
1271 /* | |
169 | 1272 * When using temp files: |
1273 * 1. * Form temp file names | |
1274 * 2. * Write the lines to a temp file | |
1275 * 3. Run the filter command on the temp file | |
1276 * 4. * Read the output of the command into the buffer | |
1277 * 5. * Delete the original lines to be filtered | |
1278 * 6. * Remove the temp files | |
1279 * | |
1280 * When writing the input with a pipe or when catching the output with a | |
1281 * pipe only need to do 3. | |
7 | 1282 */ |
1283 | |
169 | 1284 if (do_out) |
1285 shell_flags |= SHELL_DOOUT; | |
1286 | |
3482 | 1287 #ifdef FEAT_FILTERPIPE |
169 | 1288 if (!do_in && do_out && !p_stmp) |
1289 { | |
1290 /* Use a pipe to fetch stdout of the command, do not use a temp file. */ | |
1291 shell_flags |= SHELL_READ; | |
1292 curwin->w_cursor.lnum = line2; | |
1293 } | |
1294 else if (do_in && !do_out && !p_stmp) | |
7 | 1295 { |
169 | 1296 /* Use a pipe to write stdin of the command, do not use a temp file. */ |
1297 shell_flags |= SHELL_WRITE; | |
1298 curbuf->b_op_start.lnum = line1; | |
1299 curbuf->b_op_end.lnum = line2; | |
7 | 1300 } |
169 | 1301 else if (do_in && do_out && !p_stmp) |
1302 { | |
1303 /* Use a pipe to write stdin and fetch stdout of the command, do not | |
1304 * use a temp file. */ | |
1305 shell_flags |= SHELL_READ|SHELL_WRITE; | |
1306 curbuf->b_op_start.lnum = line1; | |
1307 curbuf->b_op_end.lnum = line2; | |
1308 curwin->w_cursor.lnum = line2; | |
1309 } | |
1310 else | |
1311 #endif | |
6721 | 1312 if ((do_in && (itmp = vim_tempname('i', FALSE)) == NULL) |
1313 || (do_out && (otmp = vim_tempname('o', FALSE)) == NULL)) | |
169 | 1314 { |
1315 EMSG(_(e_notmp)); | |
1316 goto filterend; | |
1317 } | |
7 | 1318 |
1319 /* | |
1320 * The writing and reading of temp files will not be shown. | |
1321 * Vi also doesn't do this and the messages are not very informative. | |
1322 */ | |
1323 ++no_wait_return; /* don't call wait_return() while busy */ | |
169 | 1324 if (itmp != NULL && buf_write(curbuf, itmp, NULL, line1, line2, eap, |
7 | 1325 FALSE, FALSE, FALSE, TRUE) == FAIL) |
1326 { | |
1327 msg_putchar('\n'); /* keep message from buf_write() */ | |
1328 --no_wait_return; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1329 #if defined(FEAT_EVAL) |
7 | 1330 if (!aborting()) |
1331 #endif | |
1332 (void)EMSG2(_(e_notcreate), itmp); /* will call wait_return */ | |
1333 goto filterend; | |
1334 } | |
1335 if (curbuf != old_curbuf) | |
1336 goto filterend; | |
1337 | |
1338 if (!do_out) | |
1339 msg_putchar('\n'); | |
1340 | |
1581 | 1341 /* Create the shell command in allocated memory. */ |
7 | 1342 cmd_buf = make_filter_cmd(cmd, itmp, otmp); |
1343 if (cmd_buf == NULL) | |
1344 goto filterend; | |
1345 | |
1346 windgoto((int)Rows - 1, 0); | |
1347 cursor_on(); | |
1348 | |
1349 /* | |
1350 * When not redirecting the output the command can write anything to the | |
1351 * screen. If 'shellredir' is equal to ">", screen may be messed up by | |
1352 * stderr output of external command. Clear the screen later. | |
1353 * If do_in is FALSE, this could be something like ":r !cat", which may | |
1354 * also mess up the screen, clear it later. | |
1355 */ | |
1356 if (!do_out || STRCMP(p_srr, ">") == 0 || !do_in) | |
1357 redraw_later_clear(); | |
1358 | |
169 | 1359 if (do_out) |
1360 { | |
1361 if (u_save((linenr_T)(line2), (linenr_T)(line2 + 1)) == FAIL) | |
1581 | 1362 { |
1363 vim_free(cmd_buf); | |
169 | 1364 goto error; |
1581 | 1365 } |
169 | 1366 redraw_curbuf_later(VALID); |
1367 } | |
1368 read_linecount = curbuf->b_ml.ml_line_count; | |
1369 | |
7 | 1370 /* |
1371 * When call_shell() fails wait_return() is called to give the user a | |
1372 * chance to read the error messages. Otherwise errors are ignored, so you | |
1373 * can see the error messages from the command that appear on stdout; use | |
1374 * 'u' to fix the text | |
1375 * Switch to cooked mode when not redirecting stdin, avoids that something | |
1376 * like ":r !cat" hangs. | |
1377 * Pass on the SHELL_DOOUT flag when the output is being redirected. | |
1378 */ | |
169 | 1379 if (call_shell(cmd_buf, SHELL_FILTER | SHELL_COOKED | shell_flags)) |
7 | 1380 { |
1381 redraw_later_clear(); | |
1382 wait_return(FALSE); | |
1383 } | |
1384 vim_free(cmd_buf); | |
1385 | |
1386 did_check_timestamps = FALSE; | |
1387 need_check_timestamps = TRUE; | |
1388 | |
1389 /* When interrupting the shell command, it may still have produced some | |
1390 * useful output. Reset got_int here, so that readfile() won't cancel | |
1391 * reading. */ | |
1392 ui_breakcheck(); | |
1393 got_int = FALSE; | |
1394 | |
1395 if (do_out) | |
1396 { | |
169 | 1397 if (otmp != NULL) |
7 | 1398 { |
169 | 1399 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
|
1400 eap, READ_FILTER) != OK) |
169 | 1401 { |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1402 #if defined(FEAT_EVAL) |
169 | 1403 if (!aborting()) |
1404 #endif | |
1405 { | |
1406 msg_putchar('\n'); | |
1407 EMSG2(_(e_notread), otmp); | |
1408 } | |
1409 goto error; | |
7 | 1410 } |
169 | 1411 if (curbuf != old_curbuf) |
1412 goto filterend; | |
7 | 1413 } |
169 | 1414 |
1415 read_linecount = curbuf->b_ml.ml_line_count - read_linecount; | |
1416 | |
1417 if (shell_flags & SHELL_READ) | |
1418 { | |
1419 curbuf->b_op_start.lnum = line2 + 1; | |
1420 curbuf->b_op_end.lnum = curwin->w_cursor.lnum; | |
1421 appended_lines_mark(line2, read_linecount); | |
1422 } | |
7 | 1423 |
1424 if (do_in) | |
1425 { | |
1426 if (cmdmod.keepmarks || vim_strchr(p_cpo, CPO_REMMARK) == NULL) | |
1427 { | |
1428 if (read_linecount >= linecount) | |
1429 /* move all marks from old lines to new lines */ | |
1430 mark_adjust(line1, line2, linecount, 0L); | |
1431 else | |
1432 { | |
1433 /* move marks from old lines to new lines, delete marks | |
1434 * that are in deleted lines */ | |
1435 mark_adjust(line1, line1 + read_linecount - 1, | |
1436 linecount, 0L); | |
1437 mark_adjust(line1 + read_linecount, line2, MAXLNUM, 0L); | |
1438 } | |
1439 } | |
1440 | |
1441 /* | |
1442 * Put cursor on first filtered line for ":range!cmd". | |
1443 * Adjust '[ and '] (set by buf_write()). | |
1444 */ | |
1445 curwin->w_cursor.lnum = line1; | |
1446 del_lines(linecount, TRUE); | |
1447 curbuf->b_op_start.lnum -= linecount; /* adjust '[ */ | |
1448 curbuf->b_op_end.lnum -= linecount; /* adjust '] */ | |
1449 write_lnum_adjust(-linecount); /* adjust last line | |
1450 for next write */ | |
100 | 1451 #ifdef FEAT_FOLDING |
1452 foldUpdate(curwin, curbuf->b_op_start.lnum, curbuf->b_op_end.lnum); | |
1453 #endif | |
7 | 1454 } |
1455 else | |
1456 { | |
1457 /* | |
1458 * Put cursor on last new line for ":r !cmd". | |
1459 */ | |
169 | 1460 linecount = curbuf->b_op_end.lnum - curbuf->b_op_start.lnum + 1; |
7 | 1461 curwin->w_cursor.lnum = curbuf->b_op_end.lnum; |
1462 } | |
100 | 1463 |
7 | 1464 beginline(BL_WHITE | BL_FIX); /* cursor on first non-blank */ |
1465 --no_wait_return; | |
1466 | |
1467 if (linecount > p_report) | |
1468 { | |
1469 if (do_in) | |
1470 { | |
274 | 1471 vim_snprintf((char *)msg_buf, sizeof(msg_buf), |
1472 _("%ld lines filtered"), (long)linecount); | |
7 | 1473 if (msg(msg_buf) && !msg_scroll) |
1474 /* save message to display it after redraw */ | |
680 | 1475 set_keep_msg(msg_buf, 0); |
7 | 1476 } |
1477 else | |
1478 msgmore((long)linecount); | |
1479 } | |
1480 } | |
1481 else | |
1482 { | |
1483 error: | |
1484 /* put cursor back in same position for ":w !cmd" */ | |
1485 curwin->w_cursor = cursor_save; | |
1486 --no_wait_return; | |
1487 wait_return(FALSE); | |
1488 } | |
1489 | |
1490 filterend: | |
1491 | |
1492 if (curbuf != old_curbuf) | |
1493 { | |
1494 --no_wait_return; | |
1495 EMSG(_("E135: *Filter* Autocommands must not change current buffer")); | |
1496 } | |
1497 if (itmp != NULL) | |
1498 mch_remove(itmp); | |
1499 if (otmp != NULL) | |
1500 mch_remove(otmp); | |
1501 vim_free(itmp); | |
1502 vim_free(otmp); | |
1503 } | |
1504 | |
1505 /* | |
1506 * Call a shell to execute a command. | |
1507 * When "cmd" is NULL start an interactive shell. | |
1508 */ | |
1509 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1510 do_shell( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1511 char_u *cmd, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1512 int flags) /* may be SHELL_DOOUT when output is redirected */ |
7 | 1513 { |
1514 buf_T *buf; | |
1515 #ifndef FEAT_GUI_MSWIN | |
1516 int save_nwr; | |
1517 #endif | |
1518 #ifdef MSWIN | |
1519 int winstart = FALSE; | |
1520 #endif | |
1521 | |
1522 /* | |
1523 * Disallow shell commands for "rvim". | |
1524 * Disallow shell commands from .exrc and .vimrc in current directory for | |
1525 * security reasons. | |
1526 */ | |
1527 if (check_restricted() || check_secure()) | |
1528 { | |
1529 msg_end(); | |
1530 return; | |
1531 } | |
1532 | |
1533 #ifdef MSWIN | |
1534 /* | |
1535 * Check if ":!start" is used. | |
1536 */ | |
1537 if (cmd != NULL) | |
1538 winstart = (STRNICMP(cmd, "start ", 6) == 0); | |
1539 #endif | |
1540 | |
1541 /* | |
1542 * For autocommands we want to get the output on the current screen, to | |
1543 * avoid having to type return below. | |
1544 */ | |
1545 msg_putchar('\r'); /* put cursor at start of line */ | |
1546 if (!autocmd_busy) | |
1547 { | |
1548 #ifdef MSWIN | |
1549 if (!winstart) | |
1550 #endif | |
1551 stoptermcap(); | |
1552 } | |
1553 #ifdef MSWIN | |
1554 if (!winstart) | |
1555 #endif | |
1556 msg_putchar('\n'); /* may shift screen one line up */ | |
1557 | |
1558 /* warning message before calling the shell */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
1559 if (p_warn && !autocmd_busy && msg_silent == 0) |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
1560 FOR_ALL_BUFFERS(buf) |
13012
8d5b451d7bab
patch 8.0.1382: get "no write since last change" message if terminal is open
Christian Brabandt <cb@256bit.org>
parents:
12942
diff
changeset
|
1561 if (bufIsChangedNotTerm(buf)) |
7 | 1562 { |
1563 #ifdef FEAT_GUI_MSWIN | |
1564 if (!winstart) | |
1565 starttermcap(); /* don't want a message box here */ | |
1566 #endif | |
1567 MSG_PUTS(_("[No write since last change]\n")); | |
1568 #ifdef FEAT_GUI_MSWIN | |
1569 if (!winstart) | |
1570 stoptermcap(); | |
1571 #endif | |
1572 break; | |
1573 } | |
1574 | |
1575 /* This windgoto is required for when the '\n' resulted in a "delete line | |
1576 * 1" command to the terminal. */ | |
1577 if (!swapping_screen()) | |
1578 windgoto(msg_row, msg_col); | |
1579 cursor_on(); | |
1580 (void)call_shell(cmd, SHELL_COOKED | flags); | |
1581 did_check_timestamps = FALSE; | |
1582 need_check_timestamps = TRUE; | |
1583 | |
1584 /* | |
1585 * put the message cursor at the end of the screen, avoids wait_return() | |
1586 * to overwrite the text that the external command showed | |
1587 */ | |
1588 if (!swapping_screen()) | |
1589 { | |
1590 msg_row = Rows - 1; | |
1591 msg_col = 0; | |
1592 } | |
1593 | |
1594 if (autocmd_busy) | |
1595 { | |
1596 if (msg_silent == 0) | |
1597 redraw_later_clear(); | |
1598 } | |
1599 else | |
1600 { | |
1601 /* | |
1602 * For ":sh" there is no need to call wait_return(), just redraw. | |
1603 * Also for the Win32 GUI (the output is in a console window). | |
1604 * Otherwise there is probably text on the screen that the user wants | |
1605 * to read before redrawing, so call wait_return(). | |
1606 */ | |
1607 #ifndef FEAT_GUI_MSWIN | |
1608 if (cmd == NULL | |
1609 # ifdef WIN3264 | |
1610 || (winstart && !need_wait_return) | |
1611 # endif | |
1612 ) | |
1613 { | |
1614 if (msg_silent == 0) | |
1615 redraw_later_clear(); | |
1616 need_wait_return = FALSE; | |
1617 } | |
1618 else | |
1619 { | |
1620 /* | |
1621 * If we switch screens when starttermcap() is called, we really | |
1622 * want to wait for "hit return to continue". | |
1623 */ | |
1624 save_nwr = no_wait_return; | |
1625 if (swapping_screen()) | |
1626 no_wait_return = FALSE; | |
1627 # ifdef AMIGA | |
1628 wait_return(term_console ? -1 : msg_silent == 0); /* see below */ | |
1629 # else | |
1630 wait_return(msg_silent == 0); | |
1631 # endif | |
1632 no_wait_return = save_nwr; | |
1633 } | |
1634 #endif /* FEAT_GUI_W32 */ | |
1635 | |
1636 #ifdef MSWIN | |
1637 if (!winstart) /* if winstart==TRUE, never stopped termcap! */ | |
1638 #endif | |
1639 starttermcap(); /* start termcap if not done by wait_return() */ | |
1640 | |
1641 /* | |
1642 * In an Amiga window redrawing is caused by asking the window size. | |
1643 * If we got an interrupt this will not work. The chance that the | |
1644 * window size is wrong is very small, but we need to redraw the | |
1645 * screen. Don't do this if ':' hit in wait_return(). THIS IS UGLY | |
1646 * but it saves an extra redraw. | |
1647 */ | |
1648 #ifdef AMIGA | |
1649 if (skip_redraw) /* ':' hit in wait_return() */ | |
1650 { | |
1651 if (msg_silent == 0) | |
1652 redraw_later_clear(); | |
1653 } | |
1654 else if (term_console) | |
1655 { | |
1656 OUT_STR(IF_EB("\033[0 q", ESC_STR "[0 q")); /* get window size */ | |
1657 if (got_int && msg_silent == 0) | |
1658 redraw_later_clear(); /* if got_int is TRUE, redraw needed */ | |
1659 else | |
1660 must_redraw = 0; /* no extra redraw needed */ | |
1661 } | |
1662 #endif | |
1663 } | |
1664 | |
1665 /* display any error messages now */ | |
1666 display_errors(); | |
725 | 1667 |
1668 apply_autocmds(EVENT_SHELLCMDPOST, NULL, NULL, FALSE, curbuf); | |
7 | 1669 } |
1670 | |
1671 /* | |
1672 * Create a shell command from a command string, input redirection file and | |
1673 * output redirection file. | |
1674 * Returns an allocated string with the shell command, or NULL for failure. | |
1675 */ | |
1676 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1677 make_filter_cmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1678 char_u *cmd, /* command */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1679 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
|
1680 char_u *otmp) /* NULL or name of output file */ |
7 | 1681 { |
1682 char_u *buf; | |
1683 long_u len; | |
5867 | 1684 |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1685 #if defined(UNIX) |
5881 | 1686 int is_fish_shell; |
5911 | 1687 char_u *shell_name = get_isolated_shell_name(); |
5881 | 1688 |
5867 | 1689 /* Account for fish's different syntax for subshells */ |
5911 | 1690 is_fish_shell = (fnamecmp(shell_name, "fish") == 0); |
1691 vim_free(shell_name); | |
5867 | 1692 if (is_fish_shell) |
1693 len = (long_u)STRLEN(cmd) + 13; /* "begin; " + "; end" + NUL */ | |
1694 else | |
1695 #endif | |
1696 len = (long_u)STRLEN(cmd) + 3; /* "()" + NUL */ | |
7 | 1697 if (itmp != NULL) |
1698 len += (long_u)STRLEN(itmp) + 9; /* " { < " + " } " */ | |
1699 if (otmp != NULL) | |
1700 len += (long_u)STRLEN(otmp) + (long_u)STRLEN(p_srr) + 2; /* " " */ | |
1701 buf = lalloc(len, TRUE); | |
1702 if (buf == NULL) | |
1703 return NULL; | |
1704 | |
7410
08e62c4fc17d
commit https://github.com/vim/vim/commit/53076830fea6df737455523f7e235bfe4f79864d
Christian Brabandt <cb@256bit.org>
parents:
7408
diff
changeset
|
1705 #if defined(UNIX) |
7 | 1706 /* |
169 | 1707 * Put braces around the command (for concatenated commands) when |
1708 * redirecting input and/or output. | |
7 | 1709 */ |
169 | 1710 if (itmp != NULL || otmp != NULL) |
5867 | 1711 { |
1712 if (is_fish_shell) | |
1713 vim_snprintf((char *)buf, len, "begin; %s; end", (char *)cmd); | |
1714 else | |
1715 vim_snprintf((char *)buf, len, "(%s)", (char *)cmd); | |
1716 } | |
169 | 1717 else |
1718 STRCPY(buf, cmd); | |
7 | 1719 if (itmp != NULL) |
1720 { | |
1721 STRCAT(buf, " < "); | |
1722 STRCAT(buf, itmp); | |
1723 } | |
1724 #else | |
1725 /* | |
5867 | 1726 * For shells that don't understand braces around commands, at least allow |
7 | 1727 * the use of commands in a pipe. |
1728 */ | |
1729 STRCPY(buf, cmd); | |
1730 if (itmp != NULL) | |
1731 { | |
1732 char_u *p; | |
1733 | |
1734 /* | |
1735 * If there is a pipe, we have to put the '<' in front of it. | |
1736 * Don't do this when 'shellquote' is not empty, otherwise the | |
1737 * redirection would be inside the quotes. | |
1738 */ | |
1739 if (*p_shq == NUL) | |
1740 { | |
1741 p = vim_strchr(buf, '|'); | |
1742 if (p != NULL) | |
1743 *p = NUL; | |
1744 } | |
1745 STRCAT(buf, " <"); /* " < " causes problems on Amiga */ | |
1746 STRCAT(buf, itmp); | |
1747 if (*p_shq == NUL) | |
1748 { | |
1749 p = vim_strchr(cmd, '|'); | |
1750 if (p != NULL) | |
1751 { | |
1752 STRCAT(buf, " "); /* insert a space before the '|' for DOS */ | |
1753 STRCAT(buf, p); | |
1754 } | |
1755 } | |
1756 } | |
1757 #endif | |
1758 if (otmp != NULL) | |
1872 | 1759 append_redir(buf, (int)len, p_srr, otmp); |
7 | 1760 |
1761 return buf; | |
1762 } | |
1763 | |
1764 /* | |
1872 | 1765 * Append output redirection for file "fname" to the end of string buffer |
1766 * "buf[buflen]" | |
7 | 1767 * Works with the 'shellredir' and 'shellpipe' options. |
1768 * The caller should make sure that there is enough room: | |
1769 * STRLEN(opt) + STRLEN(fname) + 3 | |
1770 */ | |
1771 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1772 append_redir( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1773 char_u *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1774 int buflen, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1775 char_u *opt, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1776 char_u *fname) |
7 | 1777 { |
1778 char_u *p; | |
1872 | 1779 char_u *end; |
1780 | |
1781 end = buf + STRLEN(buf); | |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1782 /* find "%s" */ |
7 | 1783 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
|
1784 { |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1785 if (p[1] == 's') /* found %s */ |
7 | 1786 break; |
5257
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1787 if (p[1] == '%') /* skip %% */ |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1788 ++p; |
e63e4b4be923
updated for version 7.4b.005
Bram Moolenaar <bram@vim.org>
parents:
5242
diff
changeset
|
1789 } |
7 | 1790 if (p != NULL) |
1791 { | |
1872 | 1792 *end = ' '; /* not really needed? Not with sh, ksh or bash */ |
1793 vim_snprintf((char *)end + 1, (size_t)(buflen - (end + 1 - buf)), | |
1794 (char *)opt, (char *)fname); | |
7 | 1795 } |
1796 else | |
1872 | 1797 vim_snprintf((char *)end, (size_t)(buflen - (end - buf)), |
7 | 1798 #ifdef FEAT_QUICKFIX |
1799 " %s %s", | |
1800 #else | |
1801 " %s%s", /* " > %s" causes problems on Amiga */ | |
1802 #endif | |
1803 (char *)opt, (char *)fname); | |
1804 } | |
1805 | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
1806 #if defined(FEAT_VIMINFO) || defined(PROTO) |
7 | 1807 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
1808 static int no_viminfo(void); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
1809 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
|
1810 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
|
1811 static void write_viminfo_barlines(vir_T *virp, FILE *fp_out); |
7 | 1812 static int viminfo_errcnt; |
1813 | |
1814 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1815 no_viminfo(void) |
7 | 1816 { |
1817 /* "vim -i NONE" does not read or write a viminfo file */ | |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
1818 return STRCMP(p_viminfofile, "NONE") == 0; |
7 | 1819 } |
1820 | |
1821 /* | |
1822 * Report an error for reading a viminfo file. | |
1823 * Count the number of errors. When there are more than 10, return TRUE. | |
1824 */ | |
1825 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1826 viminfo_error(char *errnum, char *message, char_u *line) |
7 | 1827 { |
274 | 1828 vim_snprintf((char *)IObuff, IOSIZE, _("%sviminfo: %s in line: "), |
1829 errnum, message); | |
1459 | 1830 STRNCAT(IObuff, line, IOSIZE - STRLEN(IObuff) - 1); |
156 | 1831 if (IObuff[STRLEN(IObuff) - 1] == '\n') |
1832 IObuff[STRLEN(IObuff) - 1] = NUL; | |
7 | 1833 emsg(IObuff); |
1834 if (++viminfo_errcnt >= 10) | |
1835 { | |
1836 EMSG(_("E136: viminfo: Too many errors, skipping rest of file")); | |
1837 return TRUE; | |
1838 } | |
1839 return FALSE; | |
1840 } | |
1841 | |
1842 /* | |
1843 * read_viminfo() -- Read the viminfo file. Registers etc. which are already | |
1733 | 1844 * set are not over-written unless "flags" includes VIF_FORCEIT. -- webb |
7 | 1845 */ |
1846 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1847 read_viminfo( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1848 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
|
1849 int flags) /* VIF_WANT_INFO et al. */ |
7 | 1850 { |
1851 FILE *fp; | |
1852 char_u *fname; | |
1853 | |
1854 if (no_viminfo()) | |
1855 return FAIL; | |
1856 | |
1733 | 1857 fname = viminfo_filename(file); /* get file name in allocated buffer */ |
7 | 1858 if (fname == NULL) |
1859 return FAIL; | |
1860 fp = mch_fopen((char *)fname, READBIN); | |
1861 | |
1862 if (p_verbose > 0) | |
294 | 1863 { |
1864 verbose_enter(); | |
274 | 1865 smsg((char_u *)_("Reading viminfo file \"%s\"%s%s%s"), |
1866 fname, | |
1733 | 1867 (flags & VIF_WANT_INFO) ? _(" info") : "", |
1868 (flags & VIF_WANT_MARKS) ? _(" marks") : "", | |
1869 (flags & VIF_GET_OLDFILES) ? _(" oldfiles") : "", | |
274 | 1870 fp == NULL ? _(" FAILED") : ""); |
294 | 1871 verbose_leave(); |
1872 } | |
7 | 1873 |
1874 vim_free(fname); | |
1875 if (fp == NULL) | |
1876 return FAIL; | |
1877 | |
1878 viminfo_errcnt = 0; | |
1733 | 1879 do_viminfo(fp, NULL, flags); |
7 | 1880 |
1881 fclose(fp); | |
1882 return OK; | |
1883 } | |
1884 | |
1885 /* | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1886 * 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
|
1887 * 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
|
1888 * run simultaneously, without losing any marks etc. |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
1889 * 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
|
1890 * info is written to the file. |
7 | 1891 */ |
1892 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
1893 write_viminfo(char_u *file, int forceit) |
7 | 1894 { |
1895 char_u *fname; | |
1896 FILE *fp_in = NULL; /* input viminfo file, if any */ | |
1897 FILE *fp_out = NULL; /* output viminfo file */ | |
1898 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
|
1899 stat_T st_new; /* mch_stat() of potential new file */ |
7 | 1900 #if defined(UNIX) || defined(VMS) |
1901 mode_t umask_save; | |
1902 #endif | |
1903 #ifdef UNIX | |
1904 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
|
1905 stat_T st_old; /* mch_stat() of existing viminfo file */ |
7 | 1906 #endif |
601 | 1907 #ifdef WIN3264 |
7194
272f04b41f51
commit https://github.com/vim/vim/commit/8a52ba791893fd55c5bdf98825c5b3e8892eaa62
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1908 int hidden = FALSE; |
601 | 1909 #endif |
7 | 1910 |
1911 if (no_viminfo()) | |
1912 return; | |
1913 | |
1914 fname = viminfo_filename(file); /* may set to default if NULL */ | |
1915 if (fname == NULL) | |
1916 return; | |
1917 | |
1918 fp_in = mch_fopen((char *)fname, READBIN); | |
1919 if (fp_in == NULL) | |
1920 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1921 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1922 |
7 | 1923 /* if it does exist, but we can't read it, don't try writing */ |
1924 if (mch_stat((char *)fname, &st_new) == 0) | |
1925 goto end; | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1926 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1927 /* Create the new .viminfo non-accessible for others, because it may |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1928 * contain text from non-accessible documents. It is up to the user to |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1929 * widen access (e.g. to a group). This may also fail if there is a |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1930 * race condition, then just give up. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1931 fd = mch_open((char *)fname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1932 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1933 if (fd < 0) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1934 goto end; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1935 fp_out = fdopen(fd, WRITEBIN); |
7 | 1936 } |
1937 else | |
1938 { | |
1939 /* | |
1940 * There is an existing viminfo file. Create a temporary file to | |
1941 * write the new viminfo into, in the same directory as the | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1942 * existing viminfo file, which will be renamed once all writing is |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1943 * successful. |
7 | 1944 */ |
1945 #ifdef UNIX | |
1946 /* | |
1947 * For Unix we check the owner of the file. It's not very nice to | |
1948 * overwrite a user's viminfo file after a "su root", with a | |
1949 * viminfo file that the user can't read. | |
1950 */ | |
1869 | 1951 st_old.st_dev = (dev_t)0; |
1438 | 1952 st_old.st_ino = 0; |
7 | 1953 st_old.st_mode = 0600; |
1076 | 1954 if (mch_stat((char *)fname, &st_old) == 0 |
1955 && getuid() != ROOT_UID | |
560 | 1956 && !(st_old.st_uid == getuid() |
7 | 1957 ? (st_old.st_mode & 0200) |
1958 : (st_old.st_gid == getgid() | |
1959 ? (st_old.st_mode & 0020) | |
1960 : (st_old.st_mode & 0002)))) | |
1961 { | |
944 | 1962 int tt = msg_didany; |
7 | 1963 |
1964 /* avoid a wait_return for this message, it's annoying */ | |
1965 EMSG2(_("E137: Viminfo file is not writable: %s"), fname); | |
1966 msg_didany = tt; | |
840 | 1967 fclose(fp_in); |
7 | 1968 goto end; |
1969 } | |
1970 #endif | |
601 | 1971 #ifdef WIN3264 |
1972 /* 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
|
1973 hidden = mch_ishidden(fname); |
601 | 1974 #endif |
7 | 1975 |
1976 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1977 * Make tempname, find one that does not exist yet. |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1978 * Beware of a race condition: If someone logs out and all Vim |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1979 * instances exit at the same time a temp file might be created between |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1980 * stat() and open(). Use mch_open() with O_EXCL to avoid that. |
7 | 1981 * May try twice: Once normal and once with shortname set, just in |
1982 * case somebody puts his viminfo file in an 8.3 filesystem. | |
1983 */ | |
1984 for (;;) | |
1985 { | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1986 int next_char = 'z'; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1987 char_u *wp; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
1988 |
7 | 1989 tempname = buf_modname( |
1990 #ifdef UNIX | |
1991 shortname, | |
1992 #else | |
1993 FALSE, | |
1994 #endif | |
1995 fname, | |
1996 #ifdef VMS | |
1997 (char_u *)"-tmp", | |
1998 #else | |
1999 (char_u *)".tmp", | |
2000 #endif | |
2001 FALSE); | |
2002 if (tempname == NULL) /* out of memory */ | |
2003 break; | |
2004 | |
2005 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2006 * Try a series of names. Change one character, just before |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2007 * the extension. This should also work for an 8.3 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2008 * file name, when after adding the extension it still is |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2009 * the same file as the original. |
7 | 2010 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2011 wp = tempname + STRLEN(tempname) - 5; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2012 if (wp < gettail(tempname)) /* empty file name? */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2013 wp = gettail(tempname); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2014 for (;;) |
7 | 2015 { |
2016 /* | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2017 * Check if tempfile already exists. Never overwrite an |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2018 * existing file! |
7 | 2019 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2020 if (mch_stat((char *)tempname, &st_new) == 0) |
7 | 2021 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2022 #ifdef UNIX |
7 | 2023 /* |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2024 * Check if tempfile is same as original file. May happen |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2025 * when modname() gave the same file back. E.g. silly |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2026 * link, or file name-length reached. Try again with |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2027 * shortname set. |
7 | 2028 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2029 if (!shortname && st_new.st_dev == st_old.st_dev |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2030 && st_new.st_ino == st_old.st_ino) |
7 | 2031 { |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
2032 VIM_CLEAR(tempname); |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2033 shortname = TRUE; |
7 | 2034 break; |
2035 } | |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2036 #endif |
7 | 2037 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2038 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2039 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2040 /* Try creating the file exclusively. This may fail if |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2041 * another Vim tries to do it at the same time. */ |
762 | 2042 #ifdef VMS |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2043 /* fdopen() fails for some reason */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2044 umask_save = umask(077); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2045 fp_out = mch_fopen((char *)tempname, WRITEBIN); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2046 (void)umask(umask_save); |
762 | 2047 #else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2048 int fd; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2049 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2050 /* Use mch_open() to be able to use O_NOFOLLOW and set file |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2051 * protection: |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2052 * Unix: same as original file, but strip s-bit. Reset |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2053 * umask to avoid it getting in the way. |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2054 * Others: r&w for user only. */ |
762 | 2055 # ifdef UNIX |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2056 umask_save = umask(0); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2057 fd = mch_open((char *)tempname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2058 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2059 (int)((st_old.st_mode & 0777) | 0600)); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2060 (void)umask(umask_save); |
762 | 2061 # else |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2062 fd = mch_open((char *)tempname, |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2063 O_CREAT|O_EXTRA|O_EXCL|O_WRONLY|O_NOFOLLOW, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2064 # endif |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2065 if (fd < 0) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2066 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2067 fp_out = NULL; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2068 # ifdef EEXIST |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2069 /* Avoid trying lots of names while the problem is lack |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2070 * of premission, only retry if the file already |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2071 * exists. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2072 if (errno != EEXIST) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2073 break; |
762 | 2074 # endif |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2075 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2076 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2077 fp_out = fdopen(fd, WRITEBIN); |
762 | 2078 #endif /* VMS */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2079 if (fp_out != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2080 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2081 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2082 |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2083 /* Assume file exists, try again with another name. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2084 if (next_char == 'a' - 1) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2085 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2086 /* They all exist? Must be something wrong! Don't write |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2087 * the viminfo file then. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2088 EMSG2(_("E929: Too many viminfo temp files, like %s!"), |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2089 tempname); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2090 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2091 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2092 *wp = next_char; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2093 --next_char; |
7 | 2094 } |
557 | 2095 |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2096 if (tempname != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2097 break; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2098 /* continue if shortname was set */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2099 } |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2100 |
557 | 2101 #if defined(UNIX) && defined(HAVE_FCHOWN) |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2102 if (tempname != NULL && fp_out != NULL) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2103 { |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2104 stat_T tmp_st; |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2105 |
7 | 2106 /* |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2107 * Make sure the original owner can read/write the tempfile and |
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2108 * otherwise preserve permissions, making sure the group matches. |
7 | 2109 */ |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2110 if (mch_stat((char *)tempname, &tmp_st) >= 0) |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2111 { |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2112 if (st_old.st_uid != tmp_st.st_uid) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2113 /* Changing the owner might fail, in which case the |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2114 * file will now owned by the current user, oh well. */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2115 ignored = fchown(fileno(fp_out), st_old.st_uid, -1); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2116 if (st_old.st_gid != tmp_st.st_gid |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2117 && fchown(fileno(fp_out), -1, st_old.st_gid) == -1) |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2118 /* can't set the group to what it should be, remove |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2119 * group permissions */ |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2120 (void)mch_setperm(tempname, 0600); |
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
2121 } |
12938
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2122 else |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2123 /* can't stat the file, set conservative permissions */ |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2124 (void)mch_setperm(tempname, 0600); |
1d41836582b3
patch 8.0.1345: race condition between stat() and open() for viminfo
Christian Brabandt <cb@256bit.org>
parents:
12820
diff
changeset
|
2125 } |
12942
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2126 #endif |
914fbd1d269f
patch 8.0.1347: MS-Windows: build broken by misplaced curly
Christian Brabandt <cb@256bit.org>
parents:
12938
diff
changeset
|
2127 } |
7 | 2128 |
2129 /* | |
2130 * Check if the new viminfo file can be written to. | |
2131 */ | |
2132 if (fp_out == NULL) | |
2133 { | |
2134 EMSG2(_("E138: Can't write viminfo file %s!"), | |
301 | 2135 (fp_in == NULL || tempname == NULL) ? fname : tempname); |
7 | 2136 if (fp_in != NULL) |
2137 fclose(fp_in); | |
2138 goto end; | |
2139 } | |
2140 | |
2141 if (p_verbose > 0) | |
294 | 2142 { |
2143 verbose_enter(); | |
274 | 2144 smsg((char_u *)_("Writing viminfo file \"%s\""), fname); |
294 | 2145 verbose_leave(); |
2146 } | |
7 | 2147 |
2148 viminfo_errcnt = 0; | |
1733 | 2149 do_viminfo(fp_in, fp_out, forceit ? 0 : (VIF_WANT_INFO | VIF_WANT_MARKS)); |
7 | 2150 |
8573
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2151 if (fclose(fp_out) == EOF) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2152 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2153 |
7 | 2154 if (fp_in != NULL) |
2155 { | |
2156 fclose(fp_in); | |
601 | 2157 |
6049 | 2158 /* In case of an error keep the original viminfo file. Otherwise |
2159 * 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
|
2160 if (viminfo_errcnt == 0) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2161 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2162 if (vim_rename(tempname, fname) == -1) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2163 { |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2164 ++viminfo_errcnt; |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2165 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
|
2166 } |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2167 # ifdef WIN3264 |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2168 /* 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
|
2169 else if (hidden) |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2170 mch_hide(fname); |
c76cb97073bd
commit https://github.com/vim/vim/commit/927030af23982a70580178e32806cd3638ce6e5b
Christian Brabandt <cb@256bit.org>
parents:
8560
diff
changeset
|
2171 # endif |
6049 | 2172 } |
2173 if (viminfo_errcnt > 0) | |
7 | 2174 mch_remove(tempname); |
601 | 2175 } |
2176 | |
7 | 2177 end: |
2178 vim_free(fname); | |
2179 vim_free(tempname); | |
2180 } | |
2181 | |
2182 /* | |
2183 * Get the viminfo file name to use. | |
2184 * If "file" is given and not empty, use it (has already been expanded by | |
2185 * cmdline functions). | |
2186 * Otherwise use "-i file_name", value from 'viminfo' or the default, and | |
2187 * expand environment variables. | |
2188 * Returns an allocated string. NULL when out of memory. | |
2189 */ | |
2190 static char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2191 viminfo_filename(char_u *file) |
7 | 2192 { |
2193 if (file == NULL || *file == NUL) | |
2194 { | |
11666
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2195 if (*p_viminfofile != NUL) |
5cd9ba96561d
patch 8.0.0716: not easy to start Vim cleanly
Christian Brabandt <cb@256bit.org>
parents:
11649
diff
changeset
|
2196 file = p_viminfofile; |
7 | 2197 else if ((file = find_viminfo_parameter('n')) == NULL || *file == NUL) |
2198 { | |
2199 #ifdef VIMINFO_FILE2 | |
2200 # ifdef VMS | |
2201 if (mch_getenv((char_u *)"SYS$LOGIN") == NULL) | |
2202 # else | |
12297
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2203 # ifdef MSWIN |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2204 /* Use $VIM only if $HOME is the default "C:/". */ |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2205 if (STRCMP(vim_getenv((char_u *)"HOME", NULL), "C:/") == 0 |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2206 && mch_getenv((char_u *)"HOME") == NULL) |
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2207 # else |
7 | 2208 if (mch_getenv((char_u *)"HOME") == NULL) |
12297
98586656fcae
patch 8.0.1028: MS-Windows: viminfo uses $VIM/_viminfo if $HOME not set
Christian Brabandt <cb@256bit.org>
parents:
12146
diff
changeset
|
2209 # endif |
7 | 2210 # endif |
2211 { | |
2212 /* don't use $VIM when not available. */ | |
2213 expand_env((char_u *)"$VIM", NameBuff, MAXPATHL); | |
2214 if (STRCMP("$VIM", NameBuff) != 0) /* $VIM was expanded */ | |
2215 file = (char_u *)VIMINFO_FILE2; | |
2216 else | |
2217 file = (char_u *)VIMINFO_FILE; | |
2218 } | |
2219 else | |
2220 #endif | |
2221 file = (char_u *)VIMINFO_FILE; | |
2222 } | |
2223 expand_env(file, NameBuff, MAXPATHL); | |
2224 file = NameBuff; | |
2225 } | |
2226 return vim_strsave(file); | |
2227 } | |
2228 | |
2229 /* | |
2230 * do_viminfo() -- Should only be called from read_viminfo() & write_viminfo(). | |
2231 */ | |
2232 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2233 do_viminfo(FILE *fp_in, FILE *fp_out, int flags) |
7 | 2234 { |
2235 int eof = FALSE; | |
2236 vir_T vir; | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2237 int merge = FALSE; |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2238 int do_copy_marks = FALSE; |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2239 garray_T buflist; |
7 | 2240 |
2241 if ((vir.vir_line = alloc(LSIZE)) == NULL) | |
2242 return; | |
2243 vir.vir_fd = fp_in; | |
2244 #ifdef FEAT_MBYTE | |
2245 vir.vir_conv.vc_type = CONV_NONE; | |
2246 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2247 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
|
2248 vir.vir_version = -1; |
7 | 2249 |
2250 if (fp_in != NULL) | |
2251 { | |
1733 | 2252 if (flags & VIF_WANT_INFO) |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2253 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2254 if (fp_out != NULL) |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2255 { |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2256 /* 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
|
2257 * 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
|
2258 prepare_viminfo_registers(); |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2259 prepare_viminfo_marks(); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2260 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2261 |
1733 | 2262 eof = read_viminfo_up_to_marks(&vir, |
2263 flags & VIF_FORCEIT, fp_out != NULL); | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2264 merge = TRUE; |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2265 } |
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2266 else if (flags != 0) |
7 | 2267 /* Skip info, find start of marks */ |
2268 while (!(eof = viminfo_readline(&vir)) | |
2269 && vir.vir_line[0] != '>') | |
2270 ; | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2271 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2272 do_copy_marks = (flags & |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2273 (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
|
2274 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2275 |
7 | 2276 if (fp_out != NULL) |
2277 { | |
2278 /* Write the info: */ | |
2279 fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), | |
2280 VIM_VERSION_MEDIUM); | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2281 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
|
2282 write_viminfo_version(fp_out); |
7 | 2283 #ifdef FEAT_MBYTE |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
2284 fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); |
7 | 2285 fprintf(fp_out, "*encoding=%s\n\n", p_enc); |
2286 #endif | |
2287 write_viminfo_search_pattern(fp_out); | |
2288 write_viminfo_sub_string(fp_out); | |
2289 #ifdef FEAT_CMDHIST | |
4903
2fc1f3346bfb
updated for version 7.3.1197
Bram Moolenaar <bram@vim.org>
parents:
4805
diff
changeset
|
2290 write_viminfo_history(fp_out, merge); |
7 | 2291 #endif |
2292 write_viminfo_registers(fp_out); | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2293 finish_viminfo_registers(); |
7 | 2294 #ifdef FEAT_EVAL |
2295 write_viminfo_varlist(fp_out); | |
2296 #endif | |
2297 write_viminfo_filemarks(fp_out); | |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2298 finish_viminfo_marks(); |
7 | 2299 write_viminfo_bufferlist(fp_out); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2300 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
|
2301 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2302 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2303 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
|
2304 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
|
2305 } |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2306 |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2307 if (do_copy_marks) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2308 { |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2309 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
|
2310 if (fp_out != NULL) |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2311 ga_clear(&buflist); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
2312 } |
7 | 2313 |
2314 vim_free(vir.vir_line); | |
2315 #ifdef FEAT_MBYTE | |
2316 if (vir.vir_conv.vc_type != CONV_NONE) | |
2317 convert_setup(&vir.vir_conv, NULL, NULL); | |
2318 #endif | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2319 ga_clear_strings(&vir.vir_barlines); |
7 | 2320 } |
2321 | |
2322 /* | |
2323 * read_viminfo_up_to_marks() -- Only called from do_viminfo(). Reads in the | |
2324 * first part of the viminfo file which contains everything but the marks that | |
2325 * are local to a file. Returns TRUE when end-of-file is reached. -- webb | |
2326 */ | |
2327 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2328 read_viminfo_up_to_marks( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2329 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2330 int forceit, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2331 int writing) |
7 | 2332 { |
2333 int eof; | |
2334 buf_T *buf; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2335 int got_encoding = FALSE; |
7 | 2336 |
2337 #ifdef FEAT_CMDHIST | |
4285 | 2338 prepare_viminfo_history(forceit ? 9999 : 0, writing); |
7 | 2339 #endif |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2340 |
7 | 2341 eof = viminfo_readline(virp); |
2342 while (!eof && virp->vir_line[0] != '>') | |
2343 { | |
2344 switch (virp->vir_line[0]) | |
2345 { | |
2346 /* Characters reserved for future expansion, ignored now */ | |
2347 case '+': /* "+40 /path/dir file", for running vim without args */ | |
2348 case '^': /* to be defined */ | |
2349 case '<': /* long line - ignored */ | |
2350 /* A comment or empty line. */ | |
2351 case NUL: | |
2352 case '\r': | |
2353 case '\n': | |
2354 case '#': | |
2355 eof = viminfo_readline(virp); | |
2356 break; | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2357 case '|': |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2358 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
|
2359 forceit, writing); |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2360 break; |
7 | 2361 case '*': /* "*encoding=value" */ |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2362 got_encoding = TRUE; |
7 | 2363 eof = viminfo_encoding(virp); |
2364 break; | |
2365 case '!': /* global variable */ | |
2366 #ifdef FEAT_EVAL | |
2367 eof = read_viminfo_varlist(virp, writing); | |
2368 #else | |
2369 eof = viminfo_readline(virp); | |
2370 #endif | |
2371 break; | |
2372 case '%': /* entry for buffer list */ | |
2373 eof = read_viminfo_bufferlist(virp, writing); | |
2374 break; | |
2375 case '"': | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2376 /* 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
|
2377 * lines. */ |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2378 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
|
2379 eof = read_viminfo_register(virp, forceit); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2380 else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2381 do { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2382 eof = viminfo_readline(virp); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2383 } 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
|
2384 || virp->vir_line[0] == '<')); |
7 | 2385 break; |
2386 case '/': /* Search string */ | |
2387 case '&': /* Substitute search string */ | |
2388 case '~': /* Last search string, followed by '/' or '&' */ | |
2389 eof = read_viminfo_search_pattern(virp, forceit); | |
2390 break; | |
2391 case '$': | |
2392 eof = read_viminfo_sub_string(virp, forceit); | |
2393 break; | |
2394 case ':': | |
2395 case '?': | |
2396 case '=': | |
2397 case '@': | |
2398 #ifdef FEAT_CMDHIST | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2399 /* 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
|
2400 * lines. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2401 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
|
2402 eof = read_viminfo_history(virp, writing); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2403 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2404 #endif |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2405 eof = viminfo_readline(virp); |
7 | 2406 break; |
2407 case '-': | |
2408 case '\'': | |
9297
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2409 /* 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
|
2410 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
|
2411 eof = read_viminfo_filemark(virp, forceit); |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2412 else |
9c663cda189f
commit https://github.com/vim/vim/commit/a641e1d4da3f9152c489318c06a93fcd1c746637
Christian Brabandt <cb@256bit.org>
parents:
9284
diff
changeset
|
2413 eof = viminfo_readline(virp); |
7 | 2414 break; |
2415 default: | |
2416 if (viminfo_error("E575: ", _("Illegal starting char"), | |
2417 virp->vir_line)) | |
2418 eof = TRUE; | |
2419 else | |
2420 eof = viminfo_readline(virp); | |
2421 break; | |
2422 } | |
2423 } | |
2424 | |
2425 #ifdef FEAT_CMDHIST | |
2426 /* Finish reading history items. */ | |
4285 | 2427 if (!writing) |
9256
26c7bf23ec1d
commit https://github.com/vim/vim/commit/1fd99c1ca89a3d13bb53aff4a5a8f5ee740713e5
Christian Brabandt <cb@256bit.org>
parents:
9248
diff
changeset
|
2428 finish_viminfo_history(virp); |
7 | 2429 #endif |
2430 | |
2431 /* 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
|
2432 FOR_ALL_BUFFERS(buf) |
7 | 2433 fmarks_check_names(buf); |
2434 | |
2435 return eof; | |
2436 } | |
2437 | |
2438 /* | |
2439 * Compare the 'encoding' value in the viminfo file with the current value of | |
2440 * 'encoding'. If different and the 'c' flag is in 'viminfo', setup for | |
2441 * conversion of text with iconv() in viminfo_readstring(). | |
2442 */ | |
2443 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2444 viminfo_encoding(vir_T *virp) |
7 | 2445 { |
2446 #ifdef FEAT_MBYTE | |
2447 char_u *p; | |
2448 int i; | |
2449 | |
2450 if (get_viminfo_parameter('c') != 0) | |
2451 { | |
2452 p = vim_strchr(virp->vir_line, '='); | |
2453 if (p != NULL) | |
2454 { | |
2455 /* remove trailing newline */ | |
2456 ++p; | |
2457 for (i = 0; vim_isprintc(p[i]); ++i) | |
2458 ; | |
2459 p[i] = NUL; | |
2460 | |
2461 convert_setup(&virp->vir_conv, p, p_enc); | |
2462 } | |
2463 } | |
2464 #endif | |
2465 return viminfo_readline(virp); | |
2466 } | |
2467 | |
2468 /* | |
2469 * Read a line from the viminfo file. | |
2470 * Returns TRUE for end-of-file; | |
2471 */ | |
2472 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2473 viminfo_readline(vir_T *virp) |
7 | 2474 { |
2475 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd); | |
2476 } | |
2477 | |
2478 /* | |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2479 * Check string read from viminfo file. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2480 * Remove '\n' at the end of the line. |
7 | 2481 * - replace CTRL-V CTRL-V with CTRL-V |
2482 * - replace CTRL-V 'n' with '\n' | |
2483 * | |
2484 * Check for a long line as written by viminfo_writestring(). | |
2485 * | |
2486 * Return the string in allocated memory (NULL when out of memory). | |
2487 */ | |
2488 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2489 viminfo_readstring( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2490 vir_T *virp, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2491 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
|
2492 int convert UNUSED) /* convert the string */ |
7 | 2493 { |
2494 char_u *retval; | |
2495 char_u *s, *d; | |
2496 long len; | |
2497 | |
2498 if (virp->vir_line[off] == Ctrl_V && vim_isdigit(virp->vir_line[off + 1])) | |
2499 { | |
2500 len = atol((char *)virp->vir_line + off + 1); | |
2501 retval = lalloc(len, TRUE); | |
2502 if (retval == NULL) | |
2503 { | |
2504 /* Line too long? File messed up? Skip next line. */ | |
2505 (void)vim_fgets(virp->vir_line, 10, virp->vir_fd); | |
2506 return NULL; | |
2507 } | |
2508 (void)vim_fgets(retval, (int)len, virp->vir_fd); | |
2509 s = retval + 1; /* Skip the leading '<' */ | |
2510 } | |
2511 else | |
2512 { | |
2513 retval = vim_strsave(virp->vir_line + off); | |
2514 if (retval == NULL) | |
2515 return NULL; | |
2516 s = retval; | |
2517 } | |
2518 | |
2519 /* Change CTRL-V CTRL-V to CTRL-V and CTRL-V n to \n in-place. */ | |
2520 d = retval; | |
2521 while (*s != NUL && *s != '\n') | |
2522 { | |
2523 if (s[0] == Ctrl_V && s[1] != NUL) | |
2524 { | |
2525 if (s[1] == 'n') | |
2526 *d++ = '\n'; | |
2527 else | |
2528 *d++ = Ctrl_V; | |
2529 s += 2; | |
2530 } | |
2531 else | |
2532 *d++ = *s++; | |
2533 } | |
2534 *d = NUL; | |
2535 | |
2536 #ifdef FEAT_MBYTE | |
2537 if (convert && virp->vir_conv.vc_type != CONV_NONE && *retval != NUL) | |
2538 { | |
2539 d = string_convert(&virp->vir_conv, retval, NULL); | |
2540 if (d != NULL) | |
2541 { | |
2542 vim_free(retval); | |
2543 retval = d; | |
2544 } | |
2545 } | |
2546 #endif | |
2547 | |
2548 return retval; | |
2549 } | |
2550 | |
2551 /* | |
2552 * write string to viminfo file | |
2553 * - replace CTRL-V with CTRL-V CTRL-V | |
2554 * - replace '\n' with CTRL-V 'n' | |
2555 * - add a '\n' at the end | |
2556 * | |
2557 * For a long line: | |
2558 * - write " CTRL-V <length> \n " in first line | |
2559 * - write " < <string> \n " in second line | |
2560 */ | |
2561 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2562 viminfo_writestring(FILE *fd, char_u *p) |
7 | 2563 { |
2564 int c; | |
2565 char_u *s; | |
2566 int len = 0; | |
2567 | |
2568 for (s = p; *s != NUL; ++s) | |
2569 { | |
2570 if (*s == Ctrl_V || *s == '\n') | |
2571 ++len; | |
2572 ++len; | |
2573 } | |
2574 | |
2575 /* If the string will be too long, write its length and put it in the next | |
2576 * line. Take into account that some room is needed for what comes before | |
2577 * the string (e.g., variable name). Add something to the length for the | |
2578 * '<', NL and trailing NUL. */ | |
2579 if (len > LSIZE / 2) | |
2580 fprintf(fd, IF_EB("\026%d\n<", CTRL_V_STR "%d\n<"), len + 3); | |
2581 | |
2582 while ((c = *p++) != NUL) | |
2583 { | |
2584 if (c == Ctrl_V || c == '\n') | |
2585 { | |
2586 putc(Ctrl_V, fd); | |
2587 if (c == '\n') | |
2588 c = 'n'; | |
2589 } | |
2590 putc(c, fd); | |
2591 } | |
2592 putc('\n', fd); | |
2593 } | |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2594 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2595 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2596 * 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
|
2597 * 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
|
2598 * Returns remaining characters in the line. |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2599 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2600 int |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2601 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
|
2602 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2603 char_u *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2604 int remaining = remaining_start; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2605 int len = 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2606 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2607 /* 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
|
2608 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2609 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2610 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2611 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2612 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2613 len += 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2614 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2615 ++len; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2616 } |
9978
baad324e9fbc
commit https://github.com/vim/vim/commit/257095760732597983bdd026e791907b7980e295
Christian Brabandt <cb@256bit.org>
parents:
9959
diff
changeset
|
2617 if (len > remaining - 2) |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2618 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2619 fprintf(fd, ">%d\n|<", len); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2620 remaining = LSIZE - 20; |
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 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2623 putc('"', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2624 for (p = s; *p != NUL; ++p) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2625 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2626 if (*p == NL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2627 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2628 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2629 putc('n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2630 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2631 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2632 else if (*p == '"' || *p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2633 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2634 putc('\\', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2635 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2636 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2637 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2638 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2639 putc(*p, fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2640 --remaining; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2641 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2642 if (remaining < 3) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2643 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2644 putc('\n', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2645 putc('|', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2646 putc('<', fd); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2647 /* Leave enough space for another continuation. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2648 remaining = LSIZE - 20; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2649 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2650 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2651 putc('"', fd); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2652 return remaining - 2; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2653 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2654 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2655 /* |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2656 * 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
|
2657 * 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
|
2658 * 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
|
2659 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2660 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2661 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
|
2662 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2663 char_u *p = text; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2664 char_u *nextp = NULL; |
9244
931bbf7b6ee3
commit https://github.com/vim/vim/commit/fdd82fe365d0e287bafc71f98c039cb5af8ed827
Christian Brabandt <cb@256bit.org>
parents:
9240
diff
changeset
|
2665 char_u *buf = NULL; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2666 bval_T *value; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2667 int i; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2668 int allocated = FALSE; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2669 int eof; |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2670 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2671 char_u *sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2672 int converted; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2673 #endif |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2674 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2675 while (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2676 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2677 ++p; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2678 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
|
2679 break; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2680 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
|
2681 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2682 if (*p == '>') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2683 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2684 /* 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
|
2685 * 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
|
2686 if (!allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2687 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2688 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
|
2689 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2690 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
|
2691 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2692 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
|
2693 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2694 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
|
2695 vp->bv_allocated = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2696 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2697 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2698 allocated = TRUE; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2699 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2700 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2701 if (vim_isdigit(p[1])) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2702 { |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2703 size_t len; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2704 size_t todo; |
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2705 size_t n; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2706 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2707 /* 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
|
2708 * than LSIZE: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2709 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2710 * |<"{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2711 * |<{text2}",{value} |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2712 * Length includes the quotes. |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2713 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2714 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2715 len = getdigits(&p); |
9248
9c751c33dc0f
commit https://github.com/vim/vim/commit/1d5f1d07aedb6f149f5de145b1dfd6528a769c93
Christian Brabandt <cb@256bit.org>
parents:
9244
diff
changeset
|
2716 buf = alloc((int)(len + 1)); |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2717 if (buf == NULL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2718 return TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2719 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2720 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
|
2721 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2722 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2723 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
|
2724 || virp->vir_line[1] != '<') |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2725 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2726 /* 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
|
2727 * this one starts with '|'. */ |
9270
79cb08f0d812
commit https://github.com/vim/vim/commit/62f8b4e18014b259bcde4a2845c602b0a44a3714
Christian Brabandt <cb@256bit.org>
parents:
9268
diff
changeset
|
2728 vim_free(buf); |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2729 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
|
2730 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2731 /* 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
|
2732 n = STRLEN(virp->vir_line); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2733 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
|
2734 || virp->vir_line[n - 1] == CAR)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2735 --n; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2736 n -= 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2737 if (n > todo) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2738 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2739 /* more values follow after the string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2740 nextp = virp->vir_line + 2 + todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2741 n = todo; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2742 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2743 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
|
2744 p += n; |
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 *p = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2747 p = buf; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2748 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2749 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2750 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2751 /* 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
|
2752 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2753 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2754 */ |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2755 eof = viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2756 if (eof || virp->vir_line[0] != '|' |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2757 || virp->vir_line[1] != '<') |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2758 /* 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
|
2759 * this one starts with '|'. */ |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2760 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
|
2761 p = virp->vir_line + 2; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2762 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2763 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2764 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2765 if (isdigit(*p)) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2766 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2767 value->bv_type = BVAL_NR; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2768 value->bv_nr = getdigits(&p); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2769 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2770 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2771 else if (*p == '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2772 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2773 int len = 0; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2774 char_u *s = p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2775 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2776 /* Unescape special characters in-place. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2777 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2778 while (*p != '"') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2779 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2780 if (*p == NL || *p == NUL) |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2781 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
|
2782 if (*p == '\\') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2783 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2784 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2785 if (*p == 'n') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2786 s[len++] = '\n'; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2787 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2788 s[len++] = *p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2789 ++p; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2790 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2791 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2792 s[len++] = *p++; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2793 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2794 ++p; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2795 s[len] = NUL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2796 |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2797 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2798 converted = FALSE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2799 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
|
2800 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2801 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
|
2802 if (sconv != NULL) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2803 { |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2804 if (s == buf) |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2805 vim_free(s); |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2806 s = sconv; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2807 buf = s; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2808 converted = TRUE; |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2809 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2810 } |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2811 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2812 /* 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
|
2813 * 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
|
2814 if (s != buf && allocated) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2815 s = vim_strsave(s); |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2816 value->bv_string = s; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2817 value->bv_type = BVAL_STRING; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2818 value->bv_len = len; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2819 value->bv_allocated = allocated |
9268
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2820 #ifdef FEAT_MBYTE |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2821 || converted |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2822 #endif |
a00e32b5bb39
commit https://github.com/vim/vim/commit/012270936c3c7df3bba45ad2b48938c23a2fd43a
Christian Brabandt <cb@256bit.org>
parents:
9260
diff
changeset
|
2823 ; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2824 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2825 if (nextp != NULL) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2826 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2827 /* values following a long string */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2828 p = nextp; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2829 nextp = NULL; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2830 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2831 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2832 else if (*p == ',') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2833 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2834 value->bv_type = BVAL_EMPTY; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2835 ++values->ga_len; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2836 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2837 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2838 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2839 } |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2840 return TRUE; |
9240
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 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2843 static int |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2844 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
|
2845 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2846 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
|
2847 int bartype; |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2848 garray_T values; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2849 bval_T *vp; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2850 int i; |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2851 int read_next = TRUE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2852 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2853 /* The format is: |{bartype},{value},... |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2854 * For a very long string: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2855 * |{bartype},>{length of "{text}{text2}"} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2856 * |<{text1} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2857 * |<{text2},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2858 * 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
|
2859 * |{bartype},{lots of values},> |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2860 * |<{value},{value} |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2861 */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2862 if (*p == '<') |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2863 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2864 /* Continuation line of an unrecognized item. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2865 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2866 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
|
2867 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2868 else |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2869 { |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2870 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
|
2871 bartype = getdigits(&p); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2872 switch (bartype) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2873 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2874 case BARTYPE_VERSION: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2875 /* 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
|
2876 * 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
|
2877 * doesn't understand the version. */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2878 if (!got_encoding) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2879 { |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2880 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
|
2881 vp = (bval_T *)values.ga_data; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2882 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
|
2883 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
|
2884 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2885 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2886 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2887 case BARTYPE_HISTORY: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2888 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
|
2889 handle_viminfo_history(&values, writing); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2890 break; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2891 |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2892 case BARTYPE_REGISTER: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2893 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
|
2894 handle_viminfo_register(&values, force); |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2895 break; |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2896 |
9284
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2897 case BARTYPE_MARK: |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2898 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
|
2899 handle_viminfo_mark(&values, force); |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2900 break; |
78712a2f687a
commit https://github.com/vim/vim/commit/2d35899721da0e9359a9fe1059554f8c4ea7f0c1
Christian Brabandt <cb@256bit.org>
parents:
9276
diff
changeset
|
2901 |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2902 default: |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2903 /* copy unrecognized line (for future use) */ |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2904 if (writing) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2905 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
|
2906 } |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2907 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
|
2908 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2909 vp = (bval_T *)values.ga_data + i; |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2910 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
|
2911 vim_free(vp->bv_string); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2912 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2913 ga_clear(&values); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2914 } |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2915 |
9330
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2916 if (read_next) |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2917 return viminfo_readline(virp); |
8cb76e38c346
commit https://github.com/vim/vim/commit/ecefe71704850b94df44f65fc756c1551ec68388
Christian Brabandt <cb@256bit.org>
parents:
9297
diff
changeset
|
2918 return FALSE; |
9240
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2919 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2920 |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2921 static void |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2922 write_viminfo_version(FILE *fp_out) |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2923 { |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2924 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
|
2925 BARTYPE_VERSION, VIMINFO_VERSION); |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2926 } |
636cfa97200e
commit https://github.com/vim/vim/commit/45d2eeaad66939348893b9254171067b0457cd9d
Christian Brabandt <cb@256bit.org>
parents:
9234
diff
changeset
|
2927 |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2928 static void |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2929 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
|
2930 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2931 int i; |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2932 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
|
2933 int seen_useful = FALSE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2934 char *line; |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2935 |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2936 if (gap->ga_len > 0) |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2937 { |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2938 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
|
2939 |
9412
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2940 /* 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
|
2941 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
|
2942 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2943 line = ((char **)(gap->ga_data))[i]; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2944 if (seen_useful || line[1] != '<') |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2945 { |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2946 fputs(line, fp_out); |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2947 seen_useful = TRUE; |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2948 } |
80333fcbaddf
commit https://github.com/vim/vim/commit/dec85cf75044ed94f611c825a7a0b0050a2597b9
Christian Brabandt <cb@256bit.org>
parents:
9389
diff
changeset
|
2949 } |
7664
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2950 } |
1fded31d9e04
commit https://github.com/vim/vim/commit/b20e334859334be35de4b295023a2b49bdabbfa9
Christian Brabandt <cb@256bit.org>
parents:
7447
diff
changeset
|
2951 } |
7 | 2952 #endif /* FEAT_VIMINFO */ |
2953 | |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2954 /* |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2955 * 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
|
2956 * was used. |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2957 */ |
9347
25c562442f8c
commit https://github.com/vim/vim/commit/f4fba6dcd508cb369ffa6916d9cb3fcf3d7ed548
Christian Brabandt <cb@256bit.org>
parents:
9330
diff
changeset
|
2958 time_T |
9272
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2959 vim_time(void) |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2960 { |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2961 # ifdef FEAT_EVAL |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2962 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
|
2963 # else |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2964 return time(NULL); |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2965 # endif |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2966 } |
f5d9eb512f8b
commit https://github.com/vim/vim/commit/46bbb0c4ba27395859dfeaa26938483946bb4ec2
Christian Brabandt <cb@256bit.org>
parents:
9270
diff
changeset
|
2967 |
7 | 2968 /* |
2969 * Implementation of ":fixdel", also used by get_stty(). | |
2970 * <BS> resulting <Del> | |
2971 * ^? ^H | |
2972 * not ^? ^? | |
2973 */ | |
2974 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2975 do_fixdel(exarg_T *eap UNUSED) |
7 | 2976 { |
2977 char_u *p; | |
2978 | |
2979 p = find_termcode((char_u *)"kb"); | |
2980 add_termcode((char_u *)"kD", p != NULL | |
2981 && *p == DEL ? (char_u *)CTRL_H_STR : DEL_STR, FALSE); | |
2982 } | |
2983 | |
2984 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2985 print_line_no_prefix( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2986 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2987 int use_number, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
2988 int list) |
7 | 2989 { |
13 | 2990 char_u numbuf[30]; |
7 | 2991 |
2992 if (curwin->w_p_nu || use_number) | |
2993 { | |
1872 | 2994 vim_snprintf((char *)numbuf, sizeof(numbuf), |
2995 "%*ld ", number_width(curwin), (long)lnum); | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
2996 msg_puts_attr(numbuf, HL_ATTR(HLF_N)); /* Highlight line nrs */ |
7 | 2997 } |
169 | 2998 msg_prt_line(ml_get(lnum), list); |
7 | 2999 } |
3000 | |
3001 /* | |
3002 * Print a text line. Also in silent mode ("ex -s"). | |
3003 */ | |
3004 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3005 print_line(linenr_T lnum, int use_number, int list) |
7 | 3006 { |
3007 int save_silent = silent_mode; | |
3008 | |
9980
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3009 /* apply :filter /pat/ */ |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3010 if (message_filtered(ml_get(lnum))) |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3011 return; |
b222552cf0c4
commit https://github.com/vim/vim/commit/d29459baa61819e59961804ed258efac5733ec70
Christian Brabandt <cb@256bit.org>
parents:
9978
diff
changeset
|
3012 |
169 | 3013 msg_start(); |
7 | 3014 silent_mode = FALSE; |
169 | 3015 info_message = TRUE; /* use mch_msg(), not mch_errmsg() */ |
3016 print_line_no_prefix(lnum, use_number, list); | |
7 | 3017 if (save_silent) |
3018 { | |
3019 msg_putchar('\n'); | |
3020 cursor_on(); /* msg_start() switches it off */ | |
3021 out_flush(); | |
3022 silent_mode = save_silent; | |
1798 | 3023 } |
3024 info_message = FALSE; | |
7 | 3025 } |
3026 | |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3027 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3028 rename_buffer(char_u *new_fname) |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3029 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3030 char_u *fname, *sfname, *xfname; |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3031 buf_T *buf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3032 |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3033 buf = curbuf; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3034 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
|
3035 /* buffer changed, don't change name now */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3036 if (buf != curbuf) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3037 return FAIL; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3038 #ifdef FEAT_EVAL |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3039 if (aborting()) /* autocmds may abort script processing */ |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3040 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3041 #endif |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3042 /* |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3043 * 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
|
3044 * 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
|
3045 * name, which will become the alternate file name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3046 * 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
|
3047 * name. |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3048 */ |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3049 fname = curbuf->b_ffname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3050 sfname = curbuf->b_sfname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3051 xfname = curbuf->b_fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3052 curbuf->b_ffname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3053 curbuf->b_sfname = NULL; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3054 if (setfname(curbuf, new_fname, NULL, TRUE) == FAIL) |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3055 { |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3056 curbuf->b_ffname = fname; |
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3057 curbuf->b_sfname = sfname; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3058 return FAIL; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3059 } |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3060 curbuf->b_flags |= BF_NOTEDITED; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3061 if (xfname != NULL && *xfname != NUL) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3062 { |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3063 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
|
3064 if (buf != NULL && !cmdmod.keepalt) |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3065 curwin->w_alt_fnum = buf->b_fnum; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3066 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3067 vim_free(fname); |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3068 vim_free(sfname); |
4613
219b2fcad60d
updated for version 7.3.1054
Bram Moolenaar <bram@vim.org>
parents:
4589
diff
changeset
|
3069 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3070 |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3071 /* Change directories when the 'acd' option is set. */ |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3072 DO_AUTOCHDIR; |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3073 return OK; |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3074 } |
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3075 |
7 | 3076 /* |
3077 * ":file[!] [fname]". | |
3078 */ | |
3079 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3080 ex_file(exarg_T *eap) |
7 | 3081 { |
14 | 3082 /* ":0file" removes the file name. Check for illegal uses ":3file", |
3083 * "0file name", etc. */ | |
3084 if (eap->addr_count > 0 | |
3085 && (*eap->arg != NUL | |
3086 || eap->line2 > 0 | |
3087 || eap->addr_count > 1)) | |
3088 { | |
3089 EMSG(_(e_invarg)); | |
3090 return; | |
3091 } | |
3092 | |
3093 if (*eap->arg != NUL || eap->addr_count == 1) | |
7 | 3094 { |
4589
fa39483a1363
updated for version 7.3.1042
Bram Moolenaar <bram@vim.org>
parents:
4285
diff
changeset
|
3095 if (rename_buffer(eap->arg) == FAIL) |
7 | 3096 return; |
14185
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3097 redraw_tabline = TRUE; |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3098 } |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3099 |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3100 // print file name if no argument or 'F' is not in 'shortmess' |
20468fb49f9b
patch 8.1.0110: file name not displayed with ":file"
Christian Brabandt <cb@256bit.org>
parents:
14175
diff
changeset
|
3101 if (*eap->arg == NUL || !shortmess(SHM_FILEINFO)) |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
3102 fileinfo(FALSE, FALSE, eap->forceit); |
7 | 3103 } |
3104 | |
3105 /* | |
3106 * ":update". | |
3107 */ | |
3108 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3109 ex_update(exarg_T *eap) |
7 | 3110 { |
3111 if (curbufIsChanged()) | |
3112 (void)do_write(eap); | |
3113 } | |
3114 | |
3115 /* | |
3116 * ":write" and ":saveas". | |
3117 */ | |
3118 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3119 ex_write(exarg_T *eap) |
7 | 3120 { |
3121 if (eap->usefilter) /* input lines to shell command */ | |
3122 do_bang(1, eap, FALSE, TRUE, FALSE); | |
3123 else | |
3124 (void)do_write(eap); | |
3125 } | |
3126 | |
3127 /* | |
3128 * write current buffer to file 'eap->arg' | |
3129 * if 'eap->append' is TRUE, append to the file | |
3130 * | |
3131 * if *eap->arg == NUL write to current file | |
3132 * | |
3133 * return FAIL for failure, OK otherwise | |
3134 */ | |
3135 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3136 do_write(exarg_T *eap) |
7 | 3137 { |
3138 int other; | |
3139 char_u *fname = NULL; /* init to shut up gcc */ | |
3140 char_u *ffname; | |
3141 int retval = FAIL; | |
3142 char_u *free_fname = NULL; | |
3143 #ifdef FEAT_BROWSE | |
3144 char_u *browse_file = NULL; | |
3145 #endif | |
3146 buf_T *alt_buf = NULL; | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3147 int name_was_missing; |
7 | 3148 |
3149 if (not_writing()) /* check 'write' option */ | |
3150 return FAIL; | |
3151 | |
3152 ffname = eap->arg; | |
3153 #ifdef FEAT_BROWSE | |
3154 if (cmdmod.browse) | |
3155 { | |
29 | 3156 browse_file = do_browse(BROWSE_SAVE, (char_u *)_("Save As"), ffname, |
7 | 3157 NULL, NULL, NULL, curbuf); |
3158 if (browse_file == NULL) | |
3159 goto theend; | |
3160 ffname = browse_file; | |
3161 } | |
3162 #endif | |
3163 if (*ffname == NUL) | |
3164 { | |
3165 if (eap->cmdidx == CMD_saveas) | |
3166 { | |
3167 EMSG(_(e_argreq)); | |
3168 goto theend; | |
3169 } | |
3170 other = FALSE; | |
3171 } | |
3172 else | |
3173 { | |
3174 fname = ffname; | |
3175 free_fname = fix_fname(ffname); | |
3176 /* | |
3177 * When out-of-memory, keep unexpanded file name, because we MUST be | |
3178 * able to write the file in this situation. | |
3179 */ | |
3180 if (free_fname != NULL) | |
3181 ffname = free_fname; | |
3182 other = otherfile(ffname); | |
3183 } | |
3184 | |
3185 /* | |
3186 * If we have a new file, put its name in the list of alternate file names. | |
3187 */ | |
3188 if (other) | |
3189 { | |
3190 if (vim_strchr(p_cpo, CPO_ALTWRITE) != NULL | |
3191 || eap->cmdidx == CMD_saveas) | |
3192 alt_buf = setaltfname(ffname, fname, (linenr_T)1); | |
3193 else | |
3194 alt_buf = buflist_findname(ffname); | |
3195 if (alt_buf != NULL && alt_buf->b_ml.ml_mfp != NULL) | |
3196 { | |
3197 /* Overwriting a file that is loaded in another buffer is not a | |
3198 * good idea. */ | |
315 | 3199 EMSG(_(e_bufloaded)); |
7 | 3200 goto theend; |
3201 } | |
3202 } | |
3203 | |
3204 /* | |
3205 * Writing to the current file is not allowed in readonly mode | |
3206 * and a file name is required. | |
3207 * "nofile" and "nowrite" buffers cannot be written implicitly either. | |
3208 */ | |
3209 if (!other && ( | |
3210 #ifdef FEAT_QUICKFIX | |
3211 bt_dontwrite_msg(curbuf) || | |
3212 #endif | |
3213 check_fname() == FAIL || check_readonly(&eap->forceit, curbuf))) | |
3214 goto theend; | |
3215 | |
3216 if (!other) | |
3217 { | |
3218 ffname = curbuf->b_ffname; | |
3219 fname = curbuf->b_fname; | |
3220 /* | |
3221 * Not writing the whole file is only allowed with '!'. | |
3222 */ | |
3223 if ( (eap->line1 != 1 | |
3224 || eap->line2 != curbuf->b_ml.ml_line_count) | |
3225 && !eap->forceit | |
3226 && !eap->append | |
3227 && !p_wa) | |
3228 { | |
3229 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3230 if (p_confirm || cmdmod.confirm) | |
3231 { | |
3232 if (vim_dialog_yesno(VIM_QUESTION, NULL, | |
3233 (char_u *)_("Write partial file?"), 2) != VIM_YES) | |
3234 goto theend; | |
3235 eap->forceit = TRUE; | |
3236 } | |
3237 else | |
3238 #endif | |
3239 { | |
3240 EMSG(_("E140: Use ! to write partial buffer")); | |
3241 goto theend; | |
3242 } | |
3243 } | |
3244 } | |
3245 | |
3246 if (check_overwrite(eap, curbuf, fname, ffname, other) == OK) | |
3247 { | |
3248 if (eap->cmdidx == CMD_saveas && alt_buf != NULL) | |
3249 { | |
3250 buf_T *was_curbuf = curbuf; | |
3251 | |
3252 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, curbuf); | |
21 | 3253 apply_autocmds(EVENT_BUFFILEPRE, NULL, NULL, FALSE, alt_buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3254 #ifdef FEAT_EVAL |
7 | 3255 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3256 #else |
7 | 3257 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3258 #endif |
7 | 3259 { |
3260 /* buffer changed, don't change name now */ | |
3261 retval = FAIL; | |
3262 goto theend; | |
3263 } | |
3264 /* Exchange the file names for the current and the alternate | |
3265 * buffer. This makes it look like we are now editing the buffer | |
3266 * under the new name. Must be done before buf_write(), because | |
3267 * if there is no file name and 'cpo' contains 'F', it will set | |
3268 * the file name. */ | |
3269 fname = alt_buf->b_fname; | |
3270 alt_buf->b_fname = curbuf->b_fname; | |
3271 curbuf->b_fname = fname; | |
3272 fname = alt_buf->b_ffname; | |
3273 alt_buf->b_ffname = curbuf->b_ffname; | |
3274 curbuf->b_ffname = fname; | |
3275 fname = alt_buf->b_sfname; | |
3276 alt_buf->b_sfname = curbuf->b_sfname; | |
3277 curbuf->b_sfname = fname; | |
3278 buf_name_changed(curbuf); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3279 |
7 | 3280 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, curbuf); |
21 | 3281 apply_autocmds(EVENT_BUFFILEPOST, NULL, NULL, FALSE, alt_buf); |
7 | 3282 if (!alt_buf->b_p_bl) |
3283 { | |
3284 alt_buf->b_p_bl = TRUE; | |
3285 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, alt_buf); | |
3286 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3287 #ifdef FEAT_EVAL |
7 | 3288 if (curbuf != was_curbuf || aborting()) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3289 #else |
7 | 3290 if (curbuf != was_curbuf) |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3291 #endif |
7 | 3292 { |
3293 /* buffer changed, don't write the file */ | |
3294 retval = FAIL; | |
3295 goto theend; | |
3296 } | |
634 | 3297 |
3298 /* If 'filetype' was empty try detecting it now. */ | |
3299 if (*curbuf->b_p_ft == NUL) | |
3300 { | |
819 | 3301 if (au_has_group((char_u *)"filetypedetect")) |
3302 (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
|
3303 TRUE, NULL); |
717 | 3304 do_modelines(0); |
634 | 3305 } |
2648 | 3306 |
3307 /* Autocommands may have changed buffer names, esp. when | |
3308 * 'autochdir' is set. */ | |
3309 fname = curbuf->b_sfname; | |
7 | 3310 } |
3311 | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3312 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
|
3313 |
7 | 3314 retval = buf_write(curbuf, ffname, fname, eap->line1, eap->line2, |
3315 eap, eap->append, eap->forceit, TRUE, FALSE); | |
634 | 3316 |
819 | 3317 /* After ":saveas fname" reset 'readonly'. */ |
961 | 3318 if (eap->cmdidx == CMD_saveas) |
3319 { | |
3320 if (retval == OK) | |
1806 | 3321 { |
961 | 3322 curbuf->b_p_ro = FALSE; |
1806 | 3323 redraw_tabline = TRUE; |
3324 } | |
9469
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3325 } |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3326 |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3327 /* 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
|
3328 * got changed or set. */ |
38e2fc4ee4ef
commit https://github.com/vim/vim/commit/5c71994f4ee5f87d4cce990dbc9684c70b1e108b
Christian Brabandt <cb@256bit.org>
parents:
9414
diff
changeset
|
3329 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
|
3330 { |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
3331 DO_AUTOCHDIR; |
961 | 3332 } |
7 | 3333 } |
3334 | |
3335 theend: | |
3336 #ifdef FEAT_BROWSE | |
3337 vim_free(browse_file); | |
3338 #endif | |
3339 vim_free(free_fname); | |
3340 return retval; | |
3341 } | |
3342 | |
3343 /* | |
3344 * Check if it is allowed to overwrite a file. If b_flags has BF_NOTEDITED, | |
3345 * BF_NEW or BF_READERR, check for overwriting current file. | |
3346 * May set eap->forceit if a dialog says it's OK to overwrite. | |
3347 * Return OK if it's OK, FAIL if it is not. | |
3348 */ | |
3486 | 3349 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3350 check_overwrite( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3351 exarg_T *eap, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3352 buf_T *buf, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3353 char_u *fname, /* file name to be used (can differ from |
7 | 3354 buf->ffname) */ |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3355 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
|
3356 int other) /* writing under other name */ |
7 | 3357 { |
3358 /* | |
3359 * write to other file or b_flags set or not writing the whole file: | |
3360 * overwriting only allowed with '!' | |
3361 */ | |
3362 if ( (other | |
3363 || (buf->b_flags & BF_NOTEDITED) | |
3364 || ((buf->b_flags & BF_NEW) | |
3365 && vim_strchr(p_cpo, CPO_OVERNEW) == NULL) | |
3366 || (buf->b_flags & BF_READERR)) | |
3367 && !p_wa | |
1457 | 3368 #ifdef FEAT_QUICKFIX |
3369 && !bt_nofile(buf) | |
3370 #endif | |
7 | 3371 && vim_fexists(ffname)) |
3372 { | |
460 | 3373 if (!eap->forceit && !eap->append) |
7 | 3374 { |
460 | 3375 #ifdef UNIX |
637 | 3376 /* with UNIX it is possible to open a directory */ |
460 | 3377 if (mch_isdir(ffname)) |
3378 { | |
3379 EMSG2(_(e_isadir2), ffname); | |
3380 return FAIL; | |
3381 } | |
7 | 3382 #endif |
3383 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
460 | 3384 if (p_confirm || cmdmod.confirm) |
3385 { | |
2770 | 3386 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3387 |
3388 dialog_msg(buff, _("Overwrite existing file \"%s\"?"), fname); | |
3389 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) != VIM_YES) | |
3390 return FAIL; | |
3391 eap->forceit = TRUE; | |
3392 } | |
3393 else | |
3394 #endif | |
3395 { | |
3396 EMSG(_(e_exists)); | |
7 | 3397 return FAIL; |
460 | 3398 } |
7 | 3399 } |
460 | 3400 |
3401 /* For ":w! filename" check that no swap file exists for "filename". */ | |
3402 if (other && !emsg_silent) | |
7 | 3403 { |
2770 | 3404 char_u *dir; |
460 | 3405 char_u *p; |
3406 int r; | |
3407 char_u *swapname; | |
3408 | |
3409 /* We only try the first entry in 'directory', without checking if | |
3410 * it's writable. If the "." directory is not writable the write | |
3411 * will probably fail anyway. | |
3412 * Use 'shortname' of the current buffer, since there is no buffer | |
3413 * for the written file. */ | |
3414 if (*p_dir == NUL) | |
2770 | 3415 { |
3416 dir = alloc(5); | |
3417 if (dir == NULL) | |
3418 return FAIL; | |
460 | 3419 STRCPY(dir, "."); |
2770 | 3420 } |
460 | 3421 else |
3422 { | |
2770 | 3423 dir = alloc(MAXPATHL); |
3424 if (dir == NULL) | |
3425 return FAIL; | |
460 | 3426 p = p_dir; |
3427 copy_option_part(&p, dir, MAXPATHL, ","); | |
3428 } | |
3429 swapname = makeswapname(fname, ffname, curbuf, dir); | |
2770 | 3430 vim_free(dir); |
460 | 3431 r = vim_fexists(swapname); |
3432 if (r) | |
3433 { | |
3434 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3435 if (p_confirm || cmdmod.confirm) | |
3436 { | |
2770 | 3437 char_u buff[DIALOG_MSG_SIZE]; |
460 | 3438 |
3439 dialog_msg(buff, | |
3440 _("Swap file \"%s\" exists, overwrite anyway?"), | |
3441 swapname); | |
3442 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) | |
3443 != VIM_YES) | |
819 | 3444 { |
3445 vim_free(swapname); | |
460 | 3446 return FAIL; |
819 | 3447 } |
460 | 3448 eap->forceit = TRUE; |
3449 } | |
3450 else | |
3451 #endif | |
3452 { | |
3453 EMSG2(_("E768: Swap file exists: %s (:silent! overrides)"), | |
3454 swapname); | |
819 | 3455 vim_free(swapname); |
460 | 3456 return FAIL; |
3457 } | |
3458 } | |
819 | 3459 vim_free(swapname); |
7 | 3460 } |
3461 } | |
3462 return OK; | |
3463 } | |
3464 | |
3465 /* | |
3466 * Handle ":wnext", ":wNext" and ":wprevious" commands. | |
3467 */ | |
3468 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3469 ex_wnext(exarg_T *eap) |
7 | 3470 { |
3471 int i; | |
3472 | |
3473 if (eap->cmd[1] == 'n') | |
3474 i = curwin->w_arg_idx + (int)eap->line2; | |
3475 else | |
3476 i = curwin->w_arg_idx - (int)eap->line2; | |
3477 eap->line1 = 1; | |
3478 eap->line2 = curbuf->b_ml.ml_line_count; | |
3479 if (do_write(eap) != FAIL) | |
3480 do_argfile(eap, i); | |
3481 } | |
3482 | |
3483 /* | |
3484 * ":wall", ":wqall" and ":xall": Write all changed files (and exit). | |
3485 */ | |
3486 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3487 do_wqall(exarg_T *eap) |
7 | 3488 { |
3489 buf_T *buf; | |
3490 int error = 0; | |
3491 int save_forceit = eap->forceit; | |
3492 | |
3493 if (eap->cmdidx == CMD_xall || eap->cmdidx == CMD_wqall) | |
3494 exiting = TRUE; | |
3495 | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
3496 FOR_ALL_BUFFERS(buf) |
7 | 3497 { |
13302
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3498 #ifdef FEAT_TERMINAL |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3499 if (exiting && term_job_running(buf->b_term)) |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3500 { |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3501 no_write_message_nobang(buf); |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3502 ++error; |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3503 } |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3504 else |
b5806be0b36d
patch 8.0.1525: using :wqa exits even if a job runs in a terminal window
Christian Brabandt <cb@256bit.org>
parents:
13276
diff
changeset
|
3505 #endif |
12648
cdfd6eb8bb80
patch 8.0.1202: :wall gives an errof for a terminal window
Christian Brabandt <cb@256bit.org>
parents:
12515
diff
changeset
|
3506 if (bufIsChanged(buf) && !bt_dontwrite(buf)) |
7 | 3507 { |
3508 /* | |
3509 * Check if there is a reason the buffer cannot be written: | |
3510 * 1. if the 'write' option is set | |
3511 * 2. if there is no file name (even after browsing) | |
3512 * 3. if the 'readonly' is set (even after a dialog) | |
3513 * 4. if overwriting is allowed (even after a dialog) | |
3514 */ | |
3515 if (not_writing()) | |
3516 { | |
3517 ++error; | |
3518 break; | |
3519 } | |
3520 #ifdef FEAT_BROWSE | |
3521 /* ":browse wall": ask for file name if there isn't one */ | |
3522 if (buf->b_ffname == NULL && cmdmod.browse) | |
3523 browse_save_fname(buf); | |
3524 #endif | |
3525 if (buf->b_ffname == NULL) | |
3526 { | |
3527 EMSGN(_("E141: No file name for buffer %ld"), (long)buf->b_fnum); | |
3528 ++error; | |
3529 } | |
3530 else if (check_readonly(&eap->forceit, buf) | |
3531 || check_overwrite(eap, buf, buf->b_fname, buf->b_ffname, | |
3532 FALSE) == FAIL) | |
3533 { | |
3534 ++error; | |
3535 } | |
3536 else | |
3537 { | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3538 bufref_T bufref; |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3539 |
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3540 set_bufref(&bufref, buf); |
7 | 3541 if (buf_write_all(buf, eap->forceit) == FAIL) |
3542 ++error; | |
3543 /* 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
|
3544 if (!bufref_valid(&bufref)) |
7 | 3545 buf = firstbuf; |
3546 } | |
3547 eap->forceit = save_forceit; /* check_overwrite() may set it */ | |
3548 } | |
3549 } | |
3550 if (exiting) | |
3551 { | |
3552 if (!error) | |
3553 getout(0); /* exit Vim */ | |
3554 not_exiting(); | |
3555 } | |
3556 } | |
3557 | |
3558 /* | |
3559 * Check the 'write' option. | |
3560 * Return TRUE and give a message when it's not st. | |
3561 */ | |
3562 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3563 not_writing(void) |
7 | 3564 { |
3565 if (p_write) | |
3566 return FALSE; | |
3567 EMSG(_("E142: File not written: Writing is disabled by 'write' option")); | |
3568 return TRUE; | |
3569 } | |
3570 | |
3571 /* | |
1303 | 3572 * Check if a buffer is read-only (either 'readonly' option is set or file is |
3573 * read-only). Ask for overruling in a dialog. Return TRUE and give an error | |
3574 * message when the buffer is readonly. | |
7 | 3575 */ |
3576 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3577 check_readonly(int *forceit, buf_T *buf) |
7 | 3578 { |
9387
f094d4085014
commit https://github.com/vim/vim/commit/8767f52fbfd4f053ce00a978227c95f1d7d323fe
Christian Brabandt <cb@256bit.org>
parents:
9377
diff
changeset
|
3579 stat_T st; |
1303 | 3580 |
3581 /* Handle a file being readonly when the 'readonly' option is set or when | |
3582 * the file exists and permissions are read-only. | |
3583 * We will send 0777 to check_file_readonly(), as the "perm" variable is | |
3584 * important for device checks but not here. */ | |
3585 if (!*forceit && (buf->b_p_ro | |
3586 || (mch_stat((char *)buf->b_ffname, &st) >= 0 | |
3587 && check_file_readonly(buf->b_ffname, 0777)))) | |
7 | 3588 { |
3589 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3590 if ((p_confirm || cmdmod.confirm) && buf->b_fname != NULL) | |
3591 { | |
2770 | 3592 char_u buff[DIALOG_MSG_SIZE]; |
7 | 3593 |
1303 | 3594 if (buf->b_p_ro) |
3595 dialog_msg(buff, _("'readonly' option is set for \"%s\".\nDo you wish to write anyway?"), | |
3596 buf->b_fname); | |
3597 else | |
3598 dialog_msg(buff, _("File permissions of \"%s\" are read-only.\nIt may still be possible to write it.\nDo you wish to try?"), | |
7 | 3599 buf->b_fname); |
3600 | |
3601 if (vim_dialog_yesno(VIM_QUESTION, NULL, buff, 2) == VIM_YES) | |
3602 { | |
3603 /* Set forceit, to force the writing of a readonly file */ | |
3604 *forceit = TRUE; | |
3605 return FALSE; | |
3606 } | |
3607 else | |
3608 return TRUE; | |
3609 } | |
3610 else | |
3611 #endif | |
1303 | 3612 if (buf->b_p_ro) |
7 | 3613 EMSG(_(e_readonly)); |
1303 | 3614 else |
3615 EMSG2(_("E505: \"%s\" is read-only (add ! to override)"), | |
3616 buf->b_fname); | |
7 | 3617 return TRUE; |
3618 } | |
1303 | 3619 |
7 | 3620 return FALSE; |
3621 } | |
3622 | |
3623 /* | |
632 | 3624 * Try to abandon current file and edit a new or existing file. |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3625 * "fnum" is the number of the file, if zero use ffname/sfname. |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3626 * "lnum" is the line number for the cursor in the new file (if non-zero). |
7 | 3627 * |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3628 * Return: |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3629 * GETFILE_ERROR for "normal" error, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3630 * GETFILE_NOT_WRITTEN for "not written" error, |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3631 * GETFILE_SAME_FILE for success |
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3632 * GETFILE_OPEN_OTHER for successfully opening another file. |
7 | 3633 */ |
3634 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3635 getfile( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3636 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3637 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3638 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3639 int setpm, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3640 linenr_T lnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3641 int forceit) |
7 | 3642 { |
3643 int other; | |
3644 int retval; | |
3645 char_u *free_me = NULL; | |
3646 | |
634 | 3647 if (text_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3648 return GETFILE_ERROR; |
819 | 3649 if (curbuf_locked()) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3650 return GETFILE_ERROR; |
7 | 3651 |
3652 if (fnum == 0) | |
3653 { | |
3654 /* make ffname full path, set sfname */ | |
3655 fname_expand(curbuf, &ffname, &sfname); | |
3656 other = otherfile(ffname); | |
3657 free_me = ffname; /* has been allocated, free() later */ | |
3658 } | |
3659 else | |
3660 other = (fnum != curbuf->b_fnum); | |
3661 | |
3662 if (other) | |
3663 ++no_wait_return; /* don't wait for autowrite message */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3664 if (other && !forceit && curbuf->b_nwindows == 1 && !buf_hide(curbuf) |
7 | 3665 && curbufIsChanged() && autowrite(curbuf, forceit) == FAIL) |
3666 { | |
3667 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | |
3668 if (p_confirm && p_write) | |
3669 dialog_changed(curbuf, FALSE); | |
3670 if (curbufIsChanged()) | |
3671 #endif | |
3672 { | |
3673 if (other) | |
3674 --no_wait_return; | |
12146
59c1e09cf1a9
patch 8.0.0953: get "no write since last change" error in terminal window
Christian Brabandt <cb@256bit.org>
parents:
11957
diff
changeset
|
3675 no_write_message(); |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3676 retval = GETFILE_NOT_WRITTEN; /* file has been changed */ |
7 | 3677 goto theend; |
3678 } | |
3679 } | |
3680 if (other) | |
3681 --no_wait_return; | |
3682 if (setpm) | |
3683 setpcmark(); | |
3684 if (!other) | |
3685 { | |
3686 if (lnum != 0) | |
3687 curwin->w_cursor.lnum = lnum; | |
3688 check_cursor_lnum(); | |
3689 beginline(BL_SOL | BL_FIX); | |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3690 retval = GETFILE_SAME_FILE; /* it's in the same file */ |
7 | 3691 } |
3692 else if (do_ecmd(fnum, ffname, sfname, NULL, lnum, | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
3693 (buf_hide(curbuf) ? ECMD_HIDE : 0) + (forceit ? ECMD_FORCEIT : 0), |
1743 | 3694 curwin) == OK) |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3695 retval = GETFILE_OPEN_OTHER; /* opened another file */ |
7 | 3696 else |
11476
c45fb081391c
patch 8.0.0621: :stag does not respect 'switchbuf'
Christian Brabandt <cb@256bit.org>
parents:
11372
diff
changeset
|
3697 retval = GETFILE_ERROR; /* error encountered */ |
7 | 3698 |
3699 theend: | |
3700 vim_free(free_me); | |
3701 return retval; | |
3702 } | |
3703 | |
3704 /* | |
3705 * start editing a new file | |
3706 * | |
3707 * fnum: file number; if zero use ffname/sfname | |
3708 * ffname: the file name | |
3709 * - full path if sfname used, | |
3710 * - any file name if sfname is NULL | |
3711 * - empty string to re-edit with the same file name (but may be | |
3712 * in a different directory) | |
3713 * - NULL to start an empty buffer | |
3714 * sfname: the short file name (or NULL) | |
3715 * eap: contains the command to be executed after loading the file and | |
3716 * forced 'ff' and 'fenc' | |
3717 * newlnum: if > 0: put cursor on this line number (if possible) | |
3718 * if ECMD_LASTL: use last position in loaded file | |
3719 * if ECMD_LAST: use last position in all files | |
3720 * if ECMD_ONE: use first line | |
3721 * flags: | |
3722 * ECMD_HIDE: if TRUE don't free the current buffer | |
3723 * ECMD_SET_HELP: set b_help flag of (new) buffer before opening file | |
3724 * ECMD_OLDBUF: use existing buffer if it exists | |
3725 * ECMD_FORCEIT: ! used for Ex command | |
3726 * ECMD_ADDBUF: don't edit, just add to buffer list | |
1743 | 3727 * 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
|
3728 * 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
|
3729 * of the previous buffer for "oldwin" is stored. |
7 | 3730 * |
3731 * return FAIL for failure, OK otherwise | |
3732 */ | |
3733 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3734 do_ecmd( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3735 int fnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3736 char_u *ffname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3737 char_u *sfname, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3738 exarg_T *eap, /* can be NULL! */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3739 linenr_T newlnum, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3740 int flags, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
3741 win_T *oldwin) |
7 | 3742 { |
3743 int other_file; /* TRUE if editing another file */ | |
3744 int oldbuf; /* TRUE if using existing buffer */ | |
3745 int auto_buf = FALSE; /* TRUE if autocommands brought us | |
3746 into the buffer unexpectedly */ | |
3747 char_u *new_name = NULL; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3748 #if defined(FEAT_EVAL) |
716 | 3749 int did_set_swapcommand = FALSE; |
7 | 3750 #endif |
3751 buf_T *buf; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3752 bufref_T bufref; |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3753 bufref_T old_curbuf; |
7 | 3754 char_u *free_fname = NULL; |
3755 #ifdef FEAT_BROWSE | |
3756 char_u *browse_file = NULL; | |
3757 #endif | |
3758 int retval = FAIL; | |
3759 long n; | |
6702 | 3760 pos_T orig_pos; |
7 | 3761 linenr_T topline = 0; |
3762 int newcol = -1; | |
3763 int solcol = -1; | |
3764 pos_T *pos; | |
3765 #ifdef FEAT_SUN_WORKSHOP | |
3766 char_u *cp; | |
3767 #endif | |
3768 char_u *command = NULL; | |
1185 | 3769 #ifdef FEAT_SPELL |
3770 int did_get_winopts = FALSE; | |
3771 #endif | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
3772 int readfile_flags = 0; |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
3773 int did_inc_redrawing_disabled = FALSE; |
7 | 3774 |
3775 if (eap != NULL) | |
3776 command = eap->do_ecmd_cmd; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3777 set_bufref(&old_curbuf, curbuf); |
7 | 3778 |
3779 if (fnum != 0) | |
3780 { | |
3781 if (fnum == curbuf->b_fnum) /* file is already being edited */ | |
3782 return OK; /* nothing to do */ | |
3783 other_file = TRUE; | |
3784 } | |
3785 else | |
3786 { | |
3787 #ifdef FEAT_BROWSE | |
3788 if (cmdmod.browse) | |
3789 { | |
462 | 3790 if ( |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3791 # ifdef FEAT_GUI |
462 | 3792 !gui.in_use && |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3793 # endif |
462 | 3794 au_has_group((char_u *)"FileExplorer")) |
3795 { | |
3796 /* No browsing supported but we do have the file explorer: | |
3797 * Edit the directory. */ | |
3798 if (ffname == NULL || !mch_isdir(ffname)) | |
3799 ffname = (char_u *)"."; | |
3800 } | |
3801 else | |
3802 { | |
3803 browse_file = do_browse(0, (char_u *)_("Edit File"), ffname, | |
7 | 3804 NULL, NULL, NULL, curbuf); |
462 | 3805 if (browse_file == NULL) |
3806 goto theend; | |
3807 ffname = browse_file; | |
3808 } | |
7 | 3809 } |
3810 #endif | |
3811 /* if no short name given, use ffname for short name */ | |
3812 if (sfname == NULL) | |
3813 sfname = ffname; | |
3814 #ifdef USE_FNAME_CASE | |
3815 # ifdef USE_LONG_FNAME | |
3816 if (USE_LONG_FNAME) | |
3817 # endif | |
436 | 3818 if (sfname != NULL) |
3819 fname_case(sfname, 0); /* set correct case for sfname */ | |
7 | 3820 #endif |
3821 | |
3822 if ((flags & ECMD_ADDBUF) && (ffname == NULL || *ffname == NUL)) | |
3823 goto theend; | |
3824 | |
3825 if (ffname == NULL) | |
3826 other_file = TRUE; | |
3827 /* there is no file name */ | |
3828 else if (*ffname == NUL && curbuf->b_ffname == NULL) | |
3829 other_file = FALSE; | |
3830 else | |
3831 { | |
3832 if (*ffname == NUL) /* re-edit with same file name */ | |
3833 { | |
3834 ffname = curbuf->b_ffname; | |
3835 sfname = curbuf->b_fname; | |
3836 } | |
3837 free_fname = fix_fname(ffname); /* may expand to full path name */ | |
3838 if (free_fname != NULL) | |
3839 ffname = free_fname; | |
3840 other_file = otherfile(ffname); | |
3841 #ifdef FEAT_SUN_WORKSHOP | |
3842 if (usingSunWorkShop && p_acd | |
3843 && (cp = vim_strrchr(sfname, '/')) != NULL) | |
3844 sfname = ++cp; | |
3845 #endif | |
3846 } | |
3847 } | |
3848 | |
3849 /* | |
3850 * if the file was changed we may not be allowed to abandon it | |
3851 * - if we are going to re-edit the same file | |
3852 * - or if we are the only window on this file and if ECMD_HIDE is FALSE | |
3853 */ | |
3854 if ( ((!other_file && !(flags & ECMD_OLDBUF)) | |
3855 || (curbuf->b_nwindows == 1 | |
3856 && !(flags & (ECMD_HIDE | ECMD_ADDBUF)))) | |
5464 | 3857 && check_changed(curbuf, (p_awa ? CCGD_AW : 0) |
3858 | (other_file ? 0 : CCGD_MULTWIN) | |
3859 | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0) | |
3860 | (eap == NULL ? 0 : CCGD_EXCMD))) | |
7 | 3861 { |
3862 if (fnum == 0 && other_file && ffname != NULL) | |
3863 (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum); | |
3864 goto theend; | |
3865 } | |
3866 | |
3867 /* | |
3868 * End Visual mode before switching to another buffer, so the text can be | |
3869 * copied into the GUI selection buffer. | |
3870 */ | |
3871 reset_VIsual(); | |
3872 | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3873 #if defined(FEAT_EVAL) |
716 | 3874 if ((command != NULL || newlnum > (linenr_T)0) |
3875 && *get_vim_var_str(VV_SWAPCOMMAND) == NUL) | |
3876 { | |
3877 int len; | |
3878 char_u *p; | |
3879 | |
3880 /* Set v:swapcommand for the SwapExists autocommands. */ | |
3881 if (command != NULL) | |
835 | 3882 len = (int)STRLEN(command) + 3; |
716 | 3883 else |
3884 len = 30; | |
3885 p = alloc((unsigned)len); | |
3886 if (p != NULL) | |
3887 { | |
3888 if (command != NULL) | |
3889 vim_snprintf((char *)p, len, ":%s\r", command); | |
3890 else | |
3891 vim_snprintf((char *)p, len, "%ldG", (long)newlnum); | |
3892 set_vim_var_string(VV_SWAPCOMMAND, p, -1); | |
3893 did_set_swapcommand = TRUE; | |
3894 vim_free(p); | |
3895 } | |
3896 } | |
3897 #endif | |
3898 | |
7 | 3899 /* |
3900 * If we are starting to edit another file, open a (new) buffer. | |
3901 * Otherwise we re-use the current buffer. | |
3902 */ | |
3903 if (other_file) | |
3904 { | |
3905 if (!(flags & ECMD_ADDBUF)) | |
3906 { | |
22 | 3907 if (!cmdmod.keepalt) |
3908 curwin->w_alt_fnum = curbuf->b_fnum; | |
1743 | 3909 if (oldwin != NULL) |
3910 buflist_altfpos(oldwin); | |
7 | 3911 } |
3912 | |
3913 if (fnum) | |
3914 buf = buflist_findnr(fnum); | |
3915 else | |
3916 { | |
3917 if (flags & ECMD_ADDBUF) | |
3918 { | |
3919 linenr_T tlnum = 1L; | |
3920 | |
3921 if (command != NULL) | |
3922 { | |
3923 tlnum = atol((char *)command); | |
3924 if (tlnum <= 0) | |
3925 tlnum = 1L; | |
3926 } | |
3927 (void)buflist_new(ffname, sfname, tlnum, BLN_LISTED); | |
3928 goto theend; | |
3929 } | |
3930 buf = buflist_new(ffname, sfname, 0L, | |
3931 BLN_CURBUF | ((flags & ECMD_SET_HELP) ? 0 : BLN_LISTED)); | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3932 |
5816 | 3933 /* autocommands may change curwin and curbuf */ |
3934 if (oldwin != NULL) | |
3935 oldwin = curwin; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
3936 set_bufref(&old_curbuf, curbuf); |
7 | 3937 } |
3938 if (buf == NULL) | |
3939 goto theend; | |
3940 if (buf->b_ml.ml_mfp == NULL) /* no memfile yet */ | |
3941 { | |
3942 oldbuf = FALSE; | |
3943 } | |
3944 else /* existing memfile */ | |
3945 { | |
3946 oldbuf = TRUE; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3947 set_bufref(&bufref, buf); |
7 | 3948 (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
|
3949 /* 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
|
3950 * current buffer. */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3951 if (!bufref_valid(&bufref) || curbuf != old_curbuf.br_buf) |
7 | 3952 goto theend; |
3953 #ifdef FEAT_EVAL | |
3954 if (aborting()) /* autocmds may abort script processing */ | |
3955 goto theend; | |
3956 #endif | |
3957 } | |
3958 | |
3959 /* May jump to last used line number for a loaded buffer or when asked | |
3960 * for explicitly */ | |
3961 if ((oldbuf && newlnum == ECMD_LASTL) || newlnum == ECMD_LAST) | |
3962 { | |
3963 pos = buflist_findfpos(buf); | |
3964 newlnum = pos->lnum; | |
3965 solcol = pos->col; | |
3966 } | |
3967 | |
3968 /* | |
3969 * Make the (new) buffer the one used by the current window. | |
3970 * If the old buffer becomes unused, free it if ECMD_HIDE is FALSE. | |
3971 * If the current buffer was empty and has no file name, curbuf | |
6639 | 3972 * is returned by buflist_new(), nothing to do here. |
7 | 3973 */ |
3974 if (buf != curbuf) | |
3975 { | |
3976 /* | |
3977 * Be careful: The autocommands may delete any buffer and change | |
3978 * the current buffer. | |
3979 * - If the buffer we are going to edit is deleted, give up. | |
3980 * - If the current buffer is deleted, prefer to load the new | |
3981 * buffer when loading a buffer is required. This avoids | |
3982 * loading another buffer which then must be closed again. | |
3983 * - If we ended up in the new buffer already, need to skip a few | |
3984 * things, set auto_buf. | |
3985 */ | |
3986 if (buf->b_fname != NULL) | |
3987 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
|
3988 set_bufref(&au_new_curbuf, buf); |
7 | 3989 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
|
3990 if (!bufref_valid(&au_new_curbuf)) |
7 | 3991 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
3992 /* new buffer has been deleted */ |
7 | 3993 delbuf_msg(new_name); /* frees new_name */ |
3994 goto theend; | |
3995 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
3996 #ifdef FEAT_EVAL |
7 | 3997 if (aborting()) /* autocmds may abort script processing */ |
3998 { | |
3999 vim_free(new_name); | |
4000 goto theend; | |
4001 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4002 #endif |
7 | 4003 if (buf == curbuf) /* already in new buffer */ |
4004 auto_buf = TRUE; | |
4005 else | |
4006 { | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4007 win_T *the_curwin = curwin; |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4008 |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4009 /* 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
|
4010 * 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
|
4011 the_curwin->w_closing = TRUE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4012 ++buf->b_locked; |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4013 |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4014 if (curbuf == old_curbuf.br_buf) |
7 | 4015 buf_copy_options(buf, BCO_ENTER); |
4016 | |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4017 /* 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
|
4018 * oldwin->w_buffer to NULL. */ |
825 | 4019 u_sync(FALSE); |
1743 | 4020 close_buffer(oldwin, curbuf, |
3365 | 4021 (flags & ECMD_HIDE) ? 0 : DOBUF_UNLOAD, FALSE); |
7 | 4022 |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4023 the_curwin->w_closing = FALSE; |
10106
58e6dd1d8be3
commit https://github.com/vim/vim/commit/e0ab94e7123ca7855f45919114d948ef2bc1e8c3
Christian Brabandt <cb@256bit.org>
parents:
10082
diff
changeset
|
4024 --buf->b_locked; |
3242 | 4025 |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4026 #ifdef FEAT_EVAL |
10082
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4027 /* autocmds may abort script processing */ |
7fc6103c6651
commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
4028 if (aborting() && curwin->w_buffer != NULL) |
7 | 4029 { |
4030 vim_free(new_name); | |
4031 goto theend; | |
4032 } | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4033 #endif |
7 | 4034 /* Be careful again, like above. */ |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4035 if (!bufref_valid(&au_new_curbuf)) |
7 | 4036 { |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4037 /* new buffer has been deleted */ |
7 | 4038 delbuf_msg(new_name); /* frees new_name */ |
4039 goto theend; | |
4040 } | |
4041 if (buf == curbuf) /* already in new buffer */ | |
4042 auto_buf = TRUE; | |
4043 else | |
4044 { | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4045 #ifdef FEAT_SYN_HL |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4046 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4047 * <VN> We could instead free the synblock |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4048 * and re-attach to buffer, perhaps. |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4049 */ |
11649
0f7888a5ba68
patch 8.0.0707: freeing wrong memory with certain autocommands
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
4050 if (curwin->w_buffer == NULL |
0f7888a5ba68
patch 8.0.0707: freeing wrong memory with certain autocommands
Christian Brabandt <cb@256bit.org>
parents:
11589
diff
changeset
|
4051 || curwin->w_s == &(curwin->w_buffer->b_s)) |
3480 | 4052 curwin->w_s = &(buf->b_s); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
4053 #endif |
7 | 4054 curwin->w_buffer = buf; |
4055 curbuf = buf; | |
4056 ++curbuf->b_nwindows; | |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4057 |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4058 /* Set 'fileformat', 'binary' and 'fenc' when forced. */ |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4059 if (!oldbuf && eap != NULL) |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4060 { |
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4061 set_file_options(TRUE, eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
4062 #ifdef FEAT_MBYTE |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4063 set_forced_fenc(eap); |
5242
f0361e297d9c
updated for version 7.4a.046
Bram Moolenaar <bram@vim.org>
parents:
5231
diff
changeset
|
4064 #endif |
5231
74d2f3188cd0
updated for version 7.4a.041
Bram Moolenaar <bram@vim.org>
parents:
4903
diff
changeset
|
4065 } |
7 | 4066 } |
4067 | |
4068 /* May get the window options from the last time this buffer | |
4069 * was in this window (or another window). If not used | |
4070 * before, reset the local window options to the global | |
4071 * values. Also restores old folding stuff. */ | |
1289 | 4072 get_winopts(curbuf); |
1185 | 4073 #ifdef FEAT_SPELL |
4074 did_get_winopts = TRUE; | |
4075 #endif | |
7 | 4076 } |
4077 vim_free(new_name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4078 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
|
4079 au_new_curbuf.br_buf_free_count = 0; |
7 | 4080 } |
4081 | |
4082 curwin->w_pcmark.lnum = 1; | |
4083 curwin->w_pcmark.col = 0; | |
4084 } | |
4085 else /* !other_file */ | |
4086 { | |
13553
04019fc3de93
patch 8.0.1650: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
4087 if ((flags & ECMD_ADDBUF) || check_fname() == FAIL) |
7 | 4088 goto theend; |
6531 | 4089 |
7 | 4090 oldbuf = (flags & ECMD_OLDBUF); |
4091 } | |
4092 | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4093 /* 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
|
4094 * autocommands may cause ml_get errors. */ |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4095 ++RedrawingDisabled; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4096 did_inc_redrawing_disabled = TRUE; |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4097 |
6365 | 4098 buf = curbuf; |
7 | 4099 if ((flags & ECMD_SET_HELP) || keep_help_flag) |
4100 { | |
6365 | 4101 prepare_help_buffer(); |
7 | 4102 } |
4103 else | |
4104 { | |
4105 /* Don't make a buffer listed if it's a help buffer. Useful when | |
4106 * using CTRL-O to go back to a help file. */ | |
4107 if (!curbuf->b_help) | |
4108 set_buflisted(TRUE); | |
4109 } | |
4110 | |
4111 /* If autocommands change buffers under our fingers, forget about | |
4112 * editing the file. */ | |
4113 if (buf != curbuf) | |
4114 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4115 #ifdef FEAT_EVAL |
7 | 4116 if (aborting()) /* autocmds may abort script processing */ |
4117 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4118 #endif |
7 | 4119 |
4120 /* Since we are starting to edit a file, consider the filetype to be | |
4121 * unset. Helps for when an autocommand changes files and expects syntax | |
4122 * highlighting to work in the other file. */ | |
4123 did_filetype = FALSE; | |
4124 | |
4125 /* | |
4126 * other_file oldbuf | |
4127 * FALSE FALSE re-edit same file, buffer is re-used | |
4128 * FALSE TRUE re-edit same file, nothing changes | |
4129 * TRUE FALSE start editing new file, new buffer | |
4130 * TRUE TRUE start editing in existing buffer (nothing to do) | |
4131 */ | |
4132 if (!other_file && !oldbuf) /* re-use the buffer */ | |
4133 { | |
4134 set_last_cursor(curwin); /* may set b_last_cursor */ | |
4135 if (newlnum == ECMD_LAST || newlnum == ECMD_LASTL) | |
4136 { | |
4137 newlnum = curwin->w_cursor.lnum; | |
4138 solcol = curwin->w_cursor.col; | |
4139 } | |
4140 buf = curbuf; | |
4141 if (buf->b_fname != NULL) | |
4142 new_name = vim_strsave(buf->b_fname); | |
4143 else | |
4144 new_name = NULL; | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4145 set_bufref(&bufref, buf); |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4146 |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4147 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
|
4148 { |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4149 /* 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
|
4150 * 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
|
4151 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
|
4152 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
|
4153 == FAIL) |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4154 { |
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4155 vim_free(new_name); |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4156 goto theend; |
9705
8c0871098dc9
commit https://github.com/vim/vim/commit/1e2258297bb31720bfbeb234f2dae4d1b3b04fbd
Christian Brabandt <cb@256bit.org>
parents:
9676
diff
changeset
|
4157 } |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4158 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
|
4159 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
|
4160 |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4161 /* 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
|
4162 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
|
4163 } |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4164 else |
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4165 buf_freeall(curbuf, 0); /* free all things for buffer */ |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4166 |
7 | 4167 /* If autocommands deleted the buffer we were going to re-edit, give |
4168 * 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
|
4169 if (!bufref_valid(&bufref)) |
7 | 4170 { |
4171 delbuf_msg(new_name); /* frees new_name */ | |
4172 goto theend; | |
4173 } | |
4174 vim_free(new_name); | |
4175 | |
4176 /* If autocommands change buffers under our fingers, forget about | |
4177 * re-editing the file. Should do the buf_clear_file(), but perhaps | |
4178 * the autocommands changed the buffer... */ | |
4179 if (buf != curbuf) | |
4180 goto theend; | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4181 #ifdef FEAT_EVAL |
7 | 4182 if (aborting()) /* autocmds may abort script processing */ |
4183 goto theend; | |
4184 #endif | |
4185 buf_clear_file(curbuf); | |
4186 curbuf->b_op_start.lnum = 0; /* clear '[ and '] marks */ | |
4187 curbuf->b_op_end.lnum = 0; | |
4188 } | |
4189 | |
4190 /* | |
4191 * If we get here we are sure to start editing | |
4192 */ | |
4193 /* Assume success now */ | |
4194 retval = OK; | |
4195 | |
4196 /* | |
4197 * Check if we are editing the w_arg_idx file in the argument list. | |
4198 */ | |
4199 check_arg_idx(curwin); | |
4200 | |
4201 if (!auto_buf) | |
4202 { | |
4203 /* | |
4204 * Set cursor and init window before reading the file and executing | |
4205 * autocommands. This allows for the autocommands to position the | |
4206 * cursor. | |
4207 */ | |
677 | 4208 curwin_init(); |
7 | 4209 |
4210 #ifdef FEAT_FOLDING | |
1370 | 4211 /* It's possible that all lines in the buffer changed. Need to update |
4212 * automatic folding for all windows where it's used. */ | |
4213 { | |
4214 win_T *win; | |
4215 tabpage_T *tp; | |
4216 | |
4217 FOR_ALL_TAB_WINDOWS(tp, win) | |
4218 if (win->w_buffer == curbuf) | |
4219 foldUpdateAll(win); | |
4220 } | |
7 | 4221 #endif |
4222 | |
961 | 4223 /* Change directories when the 'acd' option is set. */ |
13632
cec5137d5332
patch 8.0.1688: some macros are used without a semicolon
Christian Brabandt <cb@256bit.org>
parents:
13553
diff
changeset
|
4224 DO_AUTOCHDIR; |
961 | 4225 |
7 | 4226 /* |
4227 * Careful: open_buffer() and apply_autocmds() may change the current | |
4228 * buffer and window. | |
4229 */ | |
6702 | 4230 orig_pos = curwin->w_cursor; |
7 | 4231 topline = curwin->w_topline; |
4232 if (!oldbuf) /* need to read the file */ | |
4233 { | |
580 | 4234 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4235 swap_exists_action = SEA_DIALOG; |
4236 #endif | |
4237 curbuf->b_flags |= BF_CHECK_RO; /* set/reset 'ro' flag */ | |
4238 | |
4239 /* | |
4240 * Open the buffer and read the file. | |
4241 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4242 #if defined(FEAT_EVAL) |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4243 if (should_abort(open_buffer(FALSE, eap, readfile_flags))) |
7 | 4244 retval = FAIL; |
4245 #else | |
2394
a3aca345aafa
Add the 'undoreload' option to be able to undo a file reload.
Bram Moolenaar <bram@vim.org>
parents:
2311
diff
changeset
|
4246 (void)open_buffer(FALSE, eap, readfile_flags); |
7 | 4247 #endif |
4248 | |
580 | 4249 #if defined(HAS_SWAP_EXISTS_ACTION) |
7 | 4250 if (swap_exists_action == SEA_QUIT) |
4251 retval = FAIL; | |
9487
69ed2c9d34a6
commit https://github.com/vim/vim/commit/7c0a2f367f2507669560b1a66423155c70d2e75b
Christian Brabandt <cb@256bit.org>
parents:
9481
diff
changeset
|
4252 handle_swap_exists(&old_curbuf); |
7 | 4253 #endif |
4254 } | |
4255 else | |
4256 { | |
23 | 4257 /* Read the modelines, but only to set window-local options. Any |
4258 * buffer-local options have already been set and may have been | |
4259 * changed by the user. */ | |
717 | 4260 do_modelines(OPT_WINONLY); |
23 | 4261 |
7 | 4262 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, |
4263 &retval); | |
4264 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | |
4265 &retval); | |
4266 } | |
4267 check_arg_idx(curwin); | |
4268 | |
6702 | 4269 /* If autocommands change the cursor position or topline, we should |
14033
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4270 * keep it. Also when it moves within a line. But not when it moves |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4271 * to the first non-blank. */ |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10970
diff
changeset
|
4272 if (!EQUAL_POS(curwin->w_cursor, orig_pos)) |
7 | 4273 { |
14033
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4274 char_u *text = ml_get_curline(); |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4275 |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4276 if (curwin->w_cursor.lnum != orig_pos.lnum |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4277 || curwin->w_cursor.col != (int)(skipwhite(text) - text)) |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4278 { |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4279 newlnum = curwin->w_cursor.lnum; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4280 newcol = curwin->w_cursor.col; |
bcda3b864c31
patch 8.1.0034: cursor not restored with ":edit #"
Christian Brabandt <cb@256bit.org>
parents:
13632
diff
changeset
|
4281 } |
7 | 4282 } |
4283 if (curwin->w_topline == topline) | |
4284 topline = 0; | |
4285 | |
4286 /* Even when cursor didn't move we need to recompute topline. */ | |
4287 changed_line_abv_curs(); | |
4288 | |
4289 #ifdef FEAT_TITLE | |
4290 maketitle(); | |
4291 #endif | |
4292 } | |
4293 | |
4294 #ifdef FEAT_DIFF | |
4295 /* Tell the diff stuff that this buffer is new and/or needs updating. | |
4296 * Also needed when re-editing the same buffer, because unloading will | |
4297 * have removed it as a diff buffer. */ | |
673 | 4298 if (curwin->w_p_diff) |
4299 { | |
4300 diff_buf_add(curbuf); | |
4301 diff_invalidate(curbuf); | |
4302 } | |
7 | 4303 #endif |
4304 | |
1185 | 4305 #ifdef FEAT_SPELL |
4306 /* If the window options were changed may need to set the spell language. | |
4307 * 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
|
4308 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
|
4309 (void)did_set_spelllang(curwin); |
1185 | 4310 #endif |
4311 | |
7 | 4312 if (command == NULL) |
4313 { | |
4314 if (newcol >= 0) /* position set by autocommands */ | |
4315 { | |
4316 curwin->w_cursor.lnum = newlnum; | |
4317 curwin->w_cursor.col = newcol; | |
4318 check_cursor(); | |
4319 } | |
4320 else if (newlnum > 0) /* line number from caller or old position */ | |
4321 { | |
4322 curwin->w_cursor.lnum = newlnum; | |
4323 check_cursor_lnum(); | |
4324 if (solcol >= 0 && !p_sol) | |
4325 { | |
4326 /* 'sol' is off: Use last known column. */ | |
4327 curwin->w_cursor.col = solcol; | |
4328 check_cursor_col(); | |
4329 #ifdef FEAT_VIRTUALEDIT | |
4330 curwin->w_cursor.coladd = 0; | |
4331 #endif | |
4332 curwin->w_set_curswant = TRUE; | |
4333 } | |
4334 else | |
4335 beginline(BL_SOL | BL_FIX); | |
4336 } | |
4337 else /* no line number, go to last line in Ex mode */ | |
4338 { | |
4339 if (exmode_active) | |
4340 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
4341 beginline(BL_WHITE | BL_FIX); | |
4342 } | |
4343 } | |
4344 | |
4345 /* Check if cursors in other windows on the same buffer are still valid */ | |
4346 check_lnums(FALSE); | |
4347 | |
4348 /* | |
4349 * Did not read the file, need to show some info about the file. | |
4350 * Do this after setting the cursor. | |
4351 */ | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4352 if (oldbuf && !auto_buf) |
7 | 4353 { |
4354 int msg_scroll_save = msg_scroll; | |
4355 | |
4356 /* Obey the 'O' flag in 'cpoptions': overwrite any previous file | |
4357 * message. */ | |
4358 if (shortmess(SHM_OVERALL) && !exiting && p_verbose == 0) | |
4359 msg_scroll = FALSE; | |
4360 if (!msg_scroll) /* wait a bit when overwriting an error msg */ | |
4361 check_for_delay(FALSE); | |
4362 msg_start(); | |
4363 msg_scroll = msg_scroll_save; | |
4364 msg_scrolled_ign = TRUE; | |
4365 | |
8560
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4366 if (!shortmess(SHM_FILEINFO)) |
f3c636c673f7
commit https://github.com/vim/vim/commit/426dd0219512af5f4abeb0901b533159253ffba3
Christian Brabandt <cb@256bit.org>
parents:
8556
diff
changeset
|
4367 fileinfo(FALSE, TRUE, FALSE); |
7 | 4368 |
4369 msg_scrolled_ign = FALSE; | |
4370 } | |
4371 | |
9414
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4372 #ifdef FEAT_VIMINFO |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4373 curbuf->b_last_used = vim_time(); |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4374 #endif |
1003973c99df
commit https://github.com/vim/vim/commit/ab9c89b68dcbdb3fbda8c5a50dd90caca64f1bfd
Christian Brabandt <cb@256bit.org>
parents:
9412
diff
changeset
|
4375 |
7 | 4376 if (command != NULL) |
4377 do_cmdline(command, NULL, NULL, DOCMD_VERBOSE); | |
4378 | |
4379 #ifdef FEAT_KEYMAP | |
4380 if (curbuf->b_kmap_state & KEYMAP_INIT) | |
1869 | 4381 (void)keymap_init(); |
7 | 4382 #endif |
4383 | |
4384 --RedrawingDisabled; | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4385 did_inc_redrawing_disabled = FALSE; |
7 | 4386 if (!skip_redraw) |
4387 { | |
4388 n = p_so; | |
4389 if (topline == 0 && command == NULL) | |
4390 p_so = 999; /* force cursor halfway the window */ | |
4391 update_topline(); | |
4392 curwin->w_scbind_pos = curwin->w_topline; | |
4393 p_so = n; | |
4394 redraw_curbuf_later(NOT_VALID); /* redraw this buffer later */ | |
4395 } | |
4396 | |
4397 if (p_im) | |
4398 need_start_insertmode = TRUE; | |
4399 | |
13174
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4400 #ifdef FEAT_AUTOCHDIR |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4401 /* Change directories when the 'acd' option is set and we aren't already in |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4402 * that directory (should already be done above). Expect getcwd() to be |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4403 * faster than calling shorten_fnames() unnecessarily. */ |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4404 if (p_acd && curbuf->b_ffname != NULL) |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4405 { |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4406 char_u curdir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4407 char_u filedir[MAXPATHL]; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4408 |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4409 vim_strncpy(filedir, curbuf->b_ffname, MAXPATHL - 1); |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4410 *gettail_sep(filedir) = NUL; |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4411 if (mch_dirname(curdir, MAXPATHL) != FAIL |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4412 && vim_fnamecmp(curdir, filedir) != 0) |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4413 do_autochdir(); |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4414 } |
1bf3519889d3
patch 8.0.1461: missing another file in patch
Christian Brabandt <cb@256bit.org>
parents:
13014
diff
changeset
|
4415 #endif |
821 | 4416 |
4417 #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
|
4418 if (curbuf->b_ffname != NULL) |
7 | 4419 { |
4420 # ifdef FEAT_SUN_WORKSHOP | |
2209
d0ddf7ba1630
Included the patch to support netbeans in a terminal.
Bram Moolenaar <bram@vim.org>
parents:
2178
diff
changeset
|
4421 if (gui.in_use && usingSunWorkShop) |
7 | 4422 workshop_file_opened((char *)curbuf->b_ffname, curbuf->b_p_ro); |
4423 # endif | |
4424 # ifdef FEAT_NETBEANS_INTG | |
2210 | 4425 if ((flags & ECMD_SET_HELP) != ECMD_SET_HELP) |
34 | 4426 netbeans_file_opened(curbuf); |
7 | 4427 # endif |
4428 } | |
4429 #endif | |
4430 | |
4431 theend: | |
7941
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4432 if (did_inc_redrawing_disabled) |
98644de08f15
commit https://github.com/vim/vim/commit/ab9fc7e0cf22bcee119b62d3433cac60f405e645
Christian Brabandt <cb@256bit.org>
parents:
7850
diff
changeset
|
4433 --RedrawingDisabled; |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
4434 #if defined(FEAT_EVAL) |
716 | 4435 if (did_set_swapcommand) |
4436 set_vim_var_string(VV_SWAPCOMMAND, NULL, -1); | |
4437 #endif | |
7 | 4438 #ifdef FEAT_BROWSE |
4439 vim_free(browse_file); | |
4440 #endif | |
4441 vim_free(free_fname); | |
4442 return retval; | |
4443 } | |
4444 | |
4445 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4446 delbuf_msg(char_u *name) |
7 | 4447 { |
4448 EMSG2(_("E143: Autocommands unexpectedly deleted new buffer %s"), | |
4449 name == NULL ? (char_u *)"" : name); | |
4450 vim_free(name); | |
9481
7520696c14b0
commit https://github.com/vim/vim/commit/19ff9bf454b7492be64dd87aaf0830fa7961871e
Christian Brabandt <cb@256bit.org>
parents:
9469
diff
changeset
|
4451 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
|
4452 au_new_curbuf.br_buf_free_count = 0; |
7 | 4453 } |
4454 | |
169 | 4455 static int append_indent = 0; /* autoindent for first line */ |
4456 | |
7 | 4457 /* |
4458 * ":insert" and ":append", also used by ":change" | |
4459 */ | |
4460 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4461 ex_append(exarg_T *eap) |
7 | 4462 { |
4463 char_u *theline; | |
4464 int did_undo = FALSE; | |
4465 linenr_T lnum = eap->line2; | |
165 | 4466 int indent = 0; |
4467 char_u *p; | |
4468 int vcol; | |
4469 int empty = (curbuf->b_ml.ml_flags & ML_EMPTY); | |
7 | 4470 |
169 | 4471 /* the ! flag toggles autoindent */ |
4472 if (eap->forceit) | |
4473 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4474 | |
4475 /* First autoindent comes from the line we start on */ | |
4476 if (eap->cmdidx != CMD_change && curbuf->b_p_ai && lnum > 0) | |
4477 append_indent = get_indent_lnum(lnum); | |
4478 | |
7 | 4479 if (eap->cmdidx != CMD_append) |
4480 --lnum; | |
4481 | |
9377
5ec4fbfe38c5
commit https://github.com/vim/vim/commit/70e136e1d86ea1d795774824c7b712245912946d
Christian Brabandt <cb@256bit.org>
parents:
9347
diff
changeset
|
4482 /* when the buffer is empty need to delete the dummy line */ |
165 | 4483 if (empty && lnum == 1) |
4484 lnum = 0; | |
4485 | |
7 | 4486 State = INSERT; /* behave like in Insert mode */ |
4487 if (curbuf->b_p_iminsert == B_IMODE_LMAP) | |
4488 State |= LANGMAP; | |
165 | 4489 |
408 | 4490 for (;;) |
7 | 4491 { |
4492 msg_scroll = TRUE; | |
4493 need_wait_return = FALSE; | |
169 | 4494 if (curbuf->b_p_ai) |
4495 { | |
4496 if (append_indent >= 0) | |
4497 { | |
4498 indent = append_indent; | |
4499 append_indent = -1; | |
4500 } | |
4501 else if (lnum > 0) | |
4502 indent = get_indent_lnum(lnum); | |
4503 } | |
4504 ex_keep_indent = FALSE; | |
7 | 4505 if (eap->getline == NULL) |
169 | 4506 { |
4507 /* No getline() function, use the lines that follow. This ends | |
4508 * when there is no more. */ | |
4509 if (eap->nextcmd == NULL || *eap->nextcmd == NUL) | |
4510 break; | |
4511 p = vim_strchr(eap->nextcmd, NL); | |
4512 if (p == NULL) | |
4513 p = eap->nextcmd + STRLEN(eap->nextcmd); | |
4514 theline = vim_strnsave(eap->nextcmd, (int)(p - eap->nextcmd)); | |
4515 if (*p != NUL) | |
4516 ++p; | |
4517 eap->nextcmd = p; | |
4518 } | |
7 | 4519 else |
6164 | 4520 { |
4521 int save_State = State; | |
4522 | |
4523 /* Set State to avoid the cursor shape to be set to INSERT mode | |
4524 * when getline() returns. */ | |
4525 State = CMDLINE; | |
7 | 4526 theline = eap->getline( |
4527 #ifdef FEAT_EVAL | |
76 | 4528 eap->cstack->cs_looplevel > 0 ? -1 : |
7 | 4529 #endif |
165 | 4530 NUL, eap->cookie, indent); |
6164 | 4531 State = save_State; |
4532 } | |
7 | 4533 lines_left = Rows - 1; |
165 | 4534 if (theline == NULL) |
4535 break; | |
4536 | |
169 | 4537 /* Using ^ CTRL-D in getexmodeline() makes us repeat the indent. */ |
4538 if (ex_keep_indent) | |
4539 append_indent = indent; | |
4540 | |
165 | 4541 /* Look for the "." after automatic indent. */ |
4542 vcol = 0; | |
4543 for (p = theline; indent > vcol; ++p) | |
4544 { | |
4545 if (*p == ' ') | |
4546 ++vcol; | |
4547 else if (*p == TAB) | |
4548 vcol += 8 - vcol % 8; | |
4549 else | |
4550 break; | |
4551 } | |
4552 if ((p[0] == '.' && p[1] == NUL) | |
321 | 4553 || (!did_undo && u_save(lnum, lnum + 1 + (empty ? 1 : 0)) |
4554 == FAIL)) | |
7 | 4555 { |
4556 vim_free(theline); | |
4557 break; | |
4558 } | |
4559 | |
169 | 4560 /* don't use autoindent if nothing was typed. */ |
4561 if (p[0] == NUL) | |
4562 theline[0] = NUL; | |
4563 | |
7 | 4564 did_undo = TRUE; |
4565 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
|
4566 appended_lines_mark(lnum + (empty ? 1 : 0), 1L); |
7 | 4567 |
4568 vim_free(theline); | |
4569 ++lnum; | |
165 | 4570 |
4571 if (empty) | |
4572 { | |
4573 ml_delete(2L, FALSE); | |
4574 empty = FALSE; | |
4575 } | |
7 | 4576 } |
4577 State = NORMAL; | |
4578 | |
169 | 4579 if (eap->forceit) |
4580 curbuf->b_p_ai = !curbuf->b_p_ai; | |
4581 | |
7 | 4582 /* "start" is set to eap->line2+1 unless that position is invalid (when |
1227 | 4583 * eap->line2 pointed to the end of the buffer and nothing was appended) |
7 | 4584 * "end" is set to lnum when something has been appended, otherwise |
4585 * it is the same than "start" -- Acevedo */ | |
4586 curbuf->b_op_start.lnum = (eap->line2 < curbuf->b_ml.ml_line_count) ? | |
4587 eap->line2 + 1 : curbuf->b_ml.ml_line_count; | |
4588 if (eap->cmdidx != CMD_append) | |
4589 --curbuf->b_op_start.lnum; | |
4590 curbuf->b_op_end.lnum = (eap->line2 < lnum) | |
4591 ? lnum : curbuf->b_op_start.lnum; | |
4592 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
4593 curwin->w_cursor.lnum = lnum; | |
4594 check_cursor_lnum(); | |
4595 beginline(BL_SOL | BL_FIX); | |
4596 | |
4597 need_wait_return = FALSE; /* don't use wait_return() now */ | |
4598 ex_no_reprint = TRUE; | |
4599 } | |
4600 | |
4601 /* | |
4602 * ":change" | |
4603 */ | |
4604 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4605 ex_change(exarg_T *eap) |
7 | 4606 { |
4607 linenr_T lnum; | |
4608 | |
4609 if (eap->line2 >= eap->line1 | |
4610 && u_save(eap->line1 - 1, eap->line2 + 1) == FAIL) | |
4611 return; | |
4612 | |
169 | 4613 /* the ! flag toggles autoindent */ |
4614 if (eap->forceit ? !curbuf->b_p_ai : curbuf->b_p_ai) | |
4615 append_indent = get_indent_lnum(eap->line1); | |
4616 | |
7 | 4617 for (lnum = eap->line2; lnum >= eap->line1; --lnum) |
4618 { | |
4619 if (curbuf->b_ml.ml_flags & ML_EMPTY) /* nothing to delete */ | |
4620 break; | |
4621 ml_delete(eap->line1, FALSE); | |
4622 } | |
1929 | 4623 |
4624 /* make sure the cursor is not beyond the end of the file now */ | |
4625 check_cursor_lnum(); | |
7 | 4626 deleted_lines_mark(eap->line1, (long)(eap->line2 - lnum)); |
4627 | |
4628 /* ":append" on the line above the deleted lines. */ | |
4629 eap->line2 = eap->line1; | |
4630 ex_append(eap); | |
4631 } | |
4632 | |
4633 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4634 ex_z(exarg_T *eap) |
7 | 4635 { |
4636 char_u *x; | |
11303
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4637 long bigness; |
165 | 4638 char_u *kind; |
7 | 4639 int minus = 0; |
4640 linenr_T start, end, curs, i; | |
4641 int j; | |
4642 linenr_T lnum = eap->line2; | |
4643 | |
165 | 4644 /* Vi compatible: ":z!" uses display height, without a count uses |
4645 * 'scroll' */ | |
4646 if (eap->forceit) | |
4647 bigness = curwin->w_height; | |
10357
59d01e335858
commit https://github.com/vim/vim/commit/459ca563128f2edb7e3bb190090bbb755a56dd55
Christian Brabandt <cb@256bit.org>
parents:
10299
diff
changeset
|
4648 else if (!ONE_WINDOW) |
5678 | 4649 bigness = curwin->w_height - 3; |
4650 else | |
165 | 4651 bigness = curwin->w_p_scr * 2; |
7 | 4652 if (bigness < 1) |
4653 bigness = 1; | |
4654 | |
4655 x = eap->arg; | |
165 | 4656 kind = x; |
4657 if (*kind == '-' || *kind == '+' || *kind == '=' | |
4658 || *kind == '^' || *kind == '.') | |
4659 ++x; | |
4660 while (*x == '-' || *x == '+') | |
7 | 4661 ++x; |
4662 | |
4663 if (*x != 0) | |
4664 { | |
4665 if (!VIM_ISDIGIT(*x)) | |
4666 { | |
4667 EMSG(_("E144: non-numeric argument to :z")); | |
4668 return; | |
4669 } | |
4670 else | |
165 | 4671 { |
11303
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4672 bigness = atol((char *)x); |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4673 |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4674 /* bigness could be < 0 if atol(x) overflows. */ |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4675 if (bigness > 2 * curbuf->b_ml.ml_line_count || bigness < 0) |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4676 bigness = 2 * curbuf->b_ml.ml_line_count; |
ef32a5c74515
patch 8.0.0537: illegal memory access with :z and large count
Christian Brabandt <cb@256bit.org>
parents:
11254
diff
changeset
|
4677 |
165 | 4678 p_window = bigness; |
169 | 4679 if (*kind == '=') |
4680 bigness += 2; | |
165 | 4681 } |
7 | 4682 } |
4683 | |
165 | 4684 /* the number of '-' and '+' multiplies the distance */ |
4685 if (*kind == '-' || *kind == '+') | |
4686 for (x = kind + 1; *x == *kind; ++x) | |
4687 ; | |
4688 | |
4689 switch (*kind) | |
7 | 4690 { |
4691 case '-': | |
2881 | 4692 start = lnum - bigness * (linenr_T)(x - kind) + 1; |
4693 end = start + bigness - 1; | |
165 | 4694 curs = end; |
7 | 4695 break; |
4696 | |
4697 case '=': | |
159 | 4698 start = lnum - (bigness + 1) / 2 + 1; |
4699 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4700 curs = lnum; |
4701 minus = 1; | |
4702 break; | |
4703 | |
4704 case '^': | |
4705 start = lnum - bigness * 2; | |
4706 end = lnum - bigness; | |
4707 curs = lnum - bigness; | |
4708 break; | |
4709 | |
4710 case '.': | |
159 | 4711 start = lnum - (bigness + 1) / 2 + 1; |
4712 end = lnum + (bigness + 1) / 2 - 1; | |
7 | 4713 curs = end; |
4714 break; | |
4715 | |
4716 default: /* '+' */ | |
4717 start = lnum; | |
165 | 4718 if (*kind == '+') |
835 | 4719 start += bigness * (linenr_T)(x - kind - 1) + 1; |
169 | 4720 else if (eap->addr_count == 0) |
4721 ++start; | |
4722 end = start + bigness - 1; | |
7 | 4723 curs = end; |
4724 break; | |
4725 } | |
4726 | |
4727 if (start < 1) | |
4728 start = 1; | |
4729 | |
4730 if (end > curbuf->b_ml.ml_line_count) | |
4731 end = curbuf->b_ml.ml_line_count; | |
4732 | |
4733 if (curs > curbuf->b_ml.ml_line_count) | |
4734 curs = curbuf->b_ml.ml_line_count; | |
11372
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4735 else if (curs < 1) |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4736 curs = 1; |
7 | 4737 |
4738 for (i = start; i <= end; i++) | |
4739 { | |
4740 if (minus && i == lnum) | |
4741 { | |
4742 msg_putchar('\n'); | |
4743 | |
4744 for (j = 1; j < Columns; j++) | |
4745 msg_putchar('-'); | |
4746 } | |
4747 | |
169 | 4748 print_line(i, eap->flags & EXFLAG_NR, eap->flags & EXFLAG_LIST); |
7 | 4749 |
4750 if (minus && i == lnum) | |
4751 { | |
4752 msg_putchar('\n'); | |
4753 | |
4754 for (j = 1; j < Columns; j++) | |
4755 msg_putchar('-'); | |
4756 } | |
4757 } | |
4758 | |
11372
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4759 if (curwin->w_cursor.lnum != curs) |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4760 { |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4761 curwin->w_cursor.lnum = curs; |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4762 curwin->w_cursor.col = 0; |
1074f58e1673
patch 8.0.0571: negative line number when using :z^ in an empty buffer
Christian Brabandt <cb@256bit.org>
parents:
11303
diff
changeset
|
4763 } |
7 | 4764 ex_no_reprint = TRUE; |
4765 } | |
4766 | |
4767 /* | |
4768 * Check if the restricted flag is set. | |
4769 * If so, give an error message and return TRUE. | |
4770 * Otherwise, return FALSE. | |
4771 */ | |
4772 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4773 check_restricted(void) |
7 | 4774 { |
4775 if (restricted) | |
4776 { | |
4777 EMSG(_("E145: Shell commands not allowed in rvim")); | |
4778 return TRUE; | |
4779 } | |
4780 return FALSE; | |
4781 } | |
4782 | |
4783 /* | |
4784 * Check if the secure flag is set (.exrc or .vimrc in current directory). | |
4785 * If so, give an error message and return TRUE. | |
4786 * Otherwise, return FALSE. | |
4787 */ | |
4788 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4789 check_secure(void) |
7 | 4790 { |
4791 if (secure) | |
4792 { | |
4793 secure = 2; | |
4794 EMSG(_(e_curdir)); | |
4795 return TRUE; | |
4796 } | |
4797 #ifdef HAVE_SANDBOX | |
4798 /* | |
4799 * In the sandbox more things are not allowed, including the things | |
4800 * disallowed in secure mode. | |
4801 */ | |
4802 if (sandbox != 0) | |
4803 { | |
4804 EMSG(_(e_sandbox)); | |
4805 return TRUE; | |
4806 } | |
4807 #endif | |
4808 return FALSE; | |
4809 } | |
4810 | |
4811 static char_u *old_sub = NULL; /* previous substitute pattern */ | |
4812 static int global_need_beginline; /* call beginline() after ":g" */ | |
4813 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4814 /* |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4815 * 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
|
4816 */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4817 typedef struct { |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4818 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
|
4819 int do_ask; /* ask for confirmation */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4820 int do_count; /* count only */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4821 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
|
4822 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
|
4823 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
|
4824 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
|
4825 int do_ic; /* ignore case flag */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4826 } subflags_T; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4827 |
7 | 4828 /* do_sub() |
4829 * | |
4830 * Perform a substitution from line eap->line1 to line eap->line2 using the | |
4831 * command pointed to by eap->arg which should be of the form: | |
4832 * | |
4833 * /pattern/substitution/{flags} | |
4834 * | |
4835 * The usual escapes are supported as described in the regexp docs. | |
4836 */ | |
4837 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
4838 do_sub(exarg_T *eap) |
7 | 4839 { |
4840 linenr_T lnum; | |
4841 long i = 0; | |
4842 regmmatch_T regmatch; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4843 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
|
4844 FALSE, FALSE, 0}; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4845 #ifdef FEAT_EVAL |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4846 subflags_T subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
4847 #endif |
6789 | 4848 int save_do_all; /* remember user specified 'g' flag */ |
4849 int save_do_ask; /* remember user specified 'c' flag */ | |
7 | 4850 char_u *pat = NULL, *sub = NULL; /* init for GCC */ |
4851 int delimiter; | |
4852 int sublen; | |
4853 int got_quit = FALSE; | |
4854 int got_match = FALSE; | |
4855 int temp; | |
4856 int which_pat; | |
4857 char_u *cmd; | |
4858 int save_State; | |
165 | 4859 linenr_T first_line = 0; /* first changed line */ |
4860 linenr_T last_line= 0; /* below last changed line AFTER the | |
7 | 4861 * change */ |
4862 linenr_T old_line_count = curbuf->b_ml.ml_line_count; | |
4863 linenr_T line2; | |
165 | 4864 long nmatch; /* number of lines in match */ |
4865 char_u *sub_firstline; /* allocated copy of first sub line */ | |
4866 int endcolumn = FALSE; /* cursor in last column when done */ | |
170 | 4867 pos_T old_cursor = curwin->w_cursor; |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4868 int start_nsubs; |
3736 | 4869 #ifdef FEAT_EVAL |
5867 | 4870 int save_ma = 0; |
3736 | 4871 #endif |
7 | 4872 |
4873 cmd = eap->arg; | |
4874 if (!global_busy) | |
4875 { | |
4876 sub_nsubs = 0; | |
4877 sub_nlines = 0; | |
4878 } | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
4879 start_nsubs = sub_nsubs; |
7 | 4880 |
4881 if (eap->cmdidx == CMD_tilde) | |
4882 which_pat = RE_LAST; /* use last used regexp */ | |
4883 else | |
4884 which_pat = RE_SUBST; /* use last substitute regexp */ | |
4885 | |
4886 /* new pattern and substitution */ | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
4887 if (eap->cmd[0] == 's' && *cmd != NUL && !VIM_ISWHITE(*cmd) |
7 | 4888 && vim_strchr((char_u *)"0123456789cegriIp|\"", *cmd) == NULL) |
4889 { | |
4890 /* don't accept alphanumeric for separator */ | |
4891 if (isalpha(*cmd)) | |
4892 { | |
4893 EMSG(_("E146: Regular expressions can't be delimited by letters")); | |
4894 return; | |
4895 } | |
4896 /* | |
4897 * undocumented vi feature: | |
4898 * "\/sub/" and "\?sub?" use last used search pattern (almost like | |
4899 * //sub/r). "\&sub&" use last substitute pattern (like //sub/). | |
4900 */ | |
4901 if (*cmd == '\\') | |
4902 { | |
4903 ++cmd; | |
4904 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
4905 { | |
4906 EMSG(_(e_backslash)); | |
4907 return; | |
4908 } | |
4909 if (*cmd != '&') | |
4910 which_pat = RE_SEARCH; /* use last '/' pattern */ | |
4911 pat = (char_u *)""; /* empty search pattern */ | |
4912 delimiter = *cmd++; /* remember delimiter character */ | |
4913 } | |
4914 else /* find the end of the regexp */ | |
4915 { | |
1466 | 4916 #ifdef FEAT_FKMAP /* reverse the flow of the Farsi characters */ |
4917 if (p_altkeymap && curwin->w_p_rl) | |
4918 lrF_sub(cmd); | |
4919 #endif | |
7 | 4920 which_pat = RE_LAST; /* use last used regexp */ |
4921 delimiter = *cmd++; /* remember delimiter character */ | |
4922 pat = cmd; /* remember start of search pat */ | |
4923 cmd = skip_regexp(cmd, delimiter, p_magic, &eap->arg); | |
4924 if (cmd[0] == delimiter) /* end delimiter found */ | |
4925 *cmd++ = NUL; /* replace it with a NUL */ | |
4926 } | |
4927 | |
4928 /* | |
4929 * Small incompatibility: vi sees '\n' as end of the command, but in | |
4930 * Vim we want to use '\n' to find/substitute a NUL. | |
4931 */ | |
4932 sub = cmd; /* remember the start of the substitution */ | |
4933 | |
4934 while (cmd[0]) | |
4935 { | |
4936 if (cmd[0] == delimiter) /* end delimiter found */ | |
4937 { | |
4938 *cmd++ = NUL; /* replace it with a NUL */ | |
4939 break; | |
4940 } | |
4941 if (cmd[0] == '\\' && cmd[1] != 0) /* skip escaped characters */ | |
4942 ++cmd; | |
11127
506f5d8b7d8b
patch 8.0.0451: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11123
diff
changeset
|
4943 MB_PTR_ADV(cmd); |
7 | 4944 } |
4945 | |
4946 if (!eap->skip) | |
4947 { | |
169 | 4948 /* In POSIX vi ":s/pat/%/" uses the previous subst. string. */ |
4949 if (STRCMP(sub, "%") == 0 | |
4950 && vim_strchr(p_cpo, CPO_SUBPERCENT) != NULL) | |
4951 { | |
4952 if (old_sub == NULL) /* there is no previous command */ | |
4953 { | |
4954 EMSG(_(e_nopresub)); | |
4955 return; | |
4956 } | |
4957 sub = old_sub; | |
4958 } | |
4959 else | |
4960 { | |
4961 vim_free(old_sub); | |
4962 old_sub = vim_strsave(sub); | |
4963 } | |
7 | 4964 } |
4965 } | |
4966 else if (!eap->skip) /* use previous pattern and substitution */ | |
4967 { | |
4968 if (old_sub == NULL) /* there is no previous command */ | |
4969 { | |
4970 EMSG(_(e_nopresub)); | |
4971 return; | |
4972 } | |
4973 pat = NULL; /* search_regcomp() will use previous pattern */ | |
4974 sub = old_sub; | |
163 | 4975 |
4976 /* Vi compatibility quirk: repeating with ":s" keeps the cursor in the | |
4977 * last column after using "$". */ | |
4978 endcolumn = (curwin->w_curswant == MAXCOL); | |
7 | 4979 } |
4980 | |
5776 | 4981 /* Recognize ":%s/\n//" and turn it into a join command, which is much |
4982 * more efficient. | |
4983 * TODO: find a generic solution to make line-joining operations more | |
4984 * efficient, avoid allocating a string that grows in size. | |
4985 */ | |
5802 | 4986 if (pat != NULL && STRCMP(pat, "\\n") == 0 |
5776 | 4987 && *sub == NUL |
4988 && (*cmd == NUL || (cmd[1] == NUL && (*cmd == 'g' || *cmd == 'l' | |
4989 || *cmd == 'p' || *cmd == '#')))) | |
4990 { | |
6426 | 4991 linenr_T joined_lines_count; |
4992 | |
5776 | 4993 curwin->w_cursor.lnum = eap->line1; |
4994 if (*cmd == 'l') | |
4995 eap->flags = EXFLAG_LIST; | |
4996 else if (*cmd == '#') | |
4997 eap->flags = EXFLAG_NR; | |
4998 else if (*cmd == 'p') | |
4999 eap->flags = EXFLAG_PRINT; | |
5000 | |
6426 | 5001 /* The number of lines joined is the number of lines in the range plus |
5002 * one. One less when the last line is included. */ | |
5003 joined_lines_count = eap->line2 - eap->line1 + 1; | |
5004 if (eap->line2 < curbuf->b_ml.ml_line_count) | |
5005 ++joined_lines_count; | |
5006 if (joined_lines_count > 1) | |
5007 { | |
5008 (void)do_join(joined_lines_count, FALSE, TRUE, FALSE, TRUE); | |
5009 sub_nsubs = joined_lines_count - 1; | |
5010 sub_nlines = 1; | |
5011 (void)do_sub_msg(FALSE); | |
5012 ex_may_print(eap); | |
5013 } | |
5014 | |
5015 if (!cmdmod.keeppatterns) | |
5016 save_re_pat(RE_SUBST, pat, p_magic); | |
5017 #ifdef FEAT_CMDHIST | |
5018 /* put pattern in history */ | |
5019 add_to_history(HIST_SEARCH, pat, TRUE, NUL); | |
5020 #endif | |
5021 | |
5776 | 5022 return; |
5023 } | |
5024 | |
7 | 5025 /* |
5026 * Find trailing options. When '&' is used, keep old options. | |
5027 */ | |
5028 if (*cmd == '&') | |
5029 ++cmd; | |
5030 else | |
5031 { | |
5032 if (!p_ed) | |
5033 { | |
5034 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
|
5035 subflags.do_all = TRUE; |
7 | 5036 else |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5037 subflags.do_all = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5038 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5039 } |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5040 subflags.do_error = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5041 subflags.do_print = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5042 subflags.do_count = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5043 subflags.do_number = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5044 subflags.do_ic = 0; |
7 | 5045 } |
5046 while (*cmd) | |
5047 { | |
5048 /* | |
5049 * Note that 'g' and 'c' are always inverted, also when p_ed is off. | |
5050 * 'r' is never inverted. | |
5051 */ | |
5052 if (*cmd == 'g') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5053 subflags.do_all = !subflags.do_all; |
7 | 5054 else if (*cmd == 'c') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5055 subflags.do_ask = !subflags.do_ask; |
170 | 5056 else if (*cmd == 'n') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5057 subflags.do_count = TRUE; |
7 | 5058 else if (*cmd == 'e') |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5059 subflags.do_error = !subflags.do_error; |
7 | 5060 else if (*cmd == 'r') /* use last used regexp */ |
5061 which_pat = RE_LAST; | |
5062 else if (*cmd == 'p') | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5063 subflags.do_print = TRUE; |
169 | 5064 else if (*cmd == '#') |
5065 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5066 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5067 subflags.do_number = TRUE; |
169 | 5068 } |
5069 else if (*cmd == 'l') | |
5070 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5071 subflags.do_print = TRUE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5072 subflags.do_list = TRUE; |
169 | 5073 } |
7 | 5074 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
|
5075 subflags.do_ic = 'i'; |
7 | 5076 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
|
5077 subflags.do_ic = 'I'; |
7 | 5078 else |
5079 break; | |
5080 ++cmd; | |
5081 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5082 if (subflags.do_count) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5083 subflags.do_ask = FALSE; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5084 |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5085 save_do_all = subflags.do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5086 save_do_ask = subflags.do_ask; |
6789 | 5087 |
7 | 5088 /* |
5089 * check for a trailing count | |
5090 */ | |
5091 cmd = skipwhite(cmd); | |
5092 if (VIM_ISDIGIT(*cmd)) | |
5093 { | |
5094 i = getdigits(&cmd); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5095 if (i <= 0 && !eap->skip && subflags.do_error) |
7 | 5096 { |
5097 EMSG(_(e_zerocount)); | |
5098 return; | |
5099 } | |
5100 eap->line1 = eap->line2; | |
5101 eap->line2 += i - 1; | |
5102 if (eap->line2 > curbuf->b_ml.ml_line_count) | |
5103 eap->line2 = curbuf->b_ml.ml_line_count; | |
5104 } | |
5105 | |
5106 /* | |
5107 * check for trailing command or garbage | |
5108 */ | |
5109 cmd = skipwhite(cmd); | |
5110 if (*cmd && *cmd != '"') /* if not end-of-line or comment */ | |
5111 { | |
5112 eap->nextcmd = check_nextcmd(cmd); | |
5113 if (eap->nextcmd == NULL) | |
5114 { | |
5115 EMSG(_(e_trailing)); | |
5116 return; | |
5117 } | |
5118 } | |
5119 | |
5120 if (eap->skip) /* not executing commands, only parsing */ | |
5121 return; | |
5122 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5123 if (!subflags.do_count && !curbuf->b_p_ma) |
823 | 5124 { |
825 | 5125 /* Substitution is not allowed in non-'modifiable' buffer */ |
823 | 5126 EMSG(_(e_modifiable)); |
5127 return; | |
5128 } | |
5129 | |
7 | 5130 if (search_regcomp(pat, RE_SUBST, which_pat, SEARCH_HIS, ®match) == FAIL) |
5131 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5132 if (subflags.do_error) |
7 | 5133 EMSG(_(e_invcmd)); |
5134 return; | |
5135 } | |
5136 | |
5137 /* 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
|
5138 if (subflags.do_ic == 'i') |
7 | 5139 regmatch.rmm_ic = TRUE; |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5140 else if (subflags.do_ic == 'I') |
7 | 5141 regmatch.rmm_ic = FALSE; |
5142 | |
5143 sub_firstline = NULL; | |
5144 | |
5145 /* | |
5146 * ~ in the substitute pattern is replaced with the old pattern. | |
5147 * We do it here once to avoid it to be replaced over and over again. | |
5148 * But don't do it when it starts with "\=", then it's an expression. | |
5149 */ | |
5150 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5151 sub = regtilde(sub, p_magic); | |
5152 | |
5153 /* | |
5154 * Check for a match on each line. | |
5155 */ | |
5156 line2 = eap->line2; | |
5157 for (lnum = eap->line1; lnum <= line2 && !(got_quit | |
13380
69517d67421f
patch 8.0.1564: too many #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
13359
diff
changeset
|
5158 #if defined(FEAT_EVAL) |
7 | 5159 || aborting() |
5160 #endif | |
5161 ); ++lnum) | |
5162 { | |
1521 | 5163 nmatch = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5164 (colnr_T)0, NULL, NULL); |
7 | 5165 if (nmatch) |
5166 { | |
5167 colnr_T copycol; | |
5168 colnr_T matchcol; | |
5169 colnr_T prev_matchcol = MAXCOL; | |
5170 char_u *new_end, *new_start = NULL; | |
5171 unsigned new_start_len = 0; | |
5172 char_u *p1; | |
5173 int did_sub = FALSE; | |
5174 int lastone; | |
1872 | 5175 int len, copy_len, needed_len; |
7 | 5176 long nmatch_tl = 0; /* nr of lines matched below lnum */ |
5177 int do_again; /* do it again after joining lines */ | |
15 | 5178 int skip_match = FALSE; |
1499 | 5179 linenr_T sub_firstlnum; /* nr of first sub line */ |
7 | 5180 |
5181 /* | |
5182 * The new text is build up step by step, to avoid too much | |
5183 * copying. There are these pieces: | |
1581 | 5184 * sub_firstline The old text, unmodified. |
7 | 5185 * copycol Column in the old text where we started |
5186 * looking for a match; from here old text still | |
5187 * needs to be copied to the new text. | |
5188 * matchcol Column number of the old text where to look | |
5189 * for the next match. It's just after the | |
5190 * previous match or one further. | |
5191 * prev_matchcol Column just after the previous match (if any). | |
5192 * Mostly equal to matchcol, except for the first | |
5193 * match and after skipping an empty match. | |
5194 * regmatch.*pos Where the pattern matched in the old text. | |
5195 * new_start The new text, all that has been produced so | |
5196 * far. | |
5197 * new_end The new text, where to append new text. | |
5198 * | |
1499 | 5199 * lnum The line number where we found the start of |
5200 * the match. Can be below the line we searched | |
5201 * when there is a \n before a \zs in the | |
5202 * pattern. | |
7 | 5203 * sub_firstlnum The line number in the buffer where to look |
5204 * for a match. Can be different from "lnum" | |
5205 * when the pattern or substitute string contains | |
5206 * line breaks. | |
5207 * | |
5208 * Special situations: | |
5209 * - When the substitute string contains a line break, the part up | |
5210 * to the line break is inserted in the text, but the copy of | |
5211 * the original line is kept. "sub_firstlnum" is adjusted for | |
5212 * the inserted lines. | |
5213 * - When the matched pattern contains a line break, the old line | |
5214 * is taken from the line at the end of the pattern. The lines | |
5215 * in the match are deleted later, "sub_firstlnum" is adjusted | |
5216 * accordingly. | |
5217 * | |
5218 * The new text is built up in new_start[]. It has some extra | |
5219 * room to avoid using alloc()/free() too often. new_start_len is | |
1389 | 5220 * the length of the allocated memory at new_start. |
7 | 5221 * |
5222 * Make a copy of the old line, so it won't be taken away when | |
5223 * updating the screen or handling a multi-line match. The "old_" | |
5224 * pointers point into this copy. | |
5225 */ | |
1499 | 5226 sub_firstlnum = lnum; |
7 | 5227 copycol = 0; |
5228 matchcol = 0; | |
5229 | |
5230 /* At first match, remember current cursor position. */ | |
5231 if (!got_match) | |
5232 { | |
5233 setpcmark(); | |
5234 got_match = TRUE; | |
5235 } | |
5236 | |
5237 /* | |
5238 * Loop until nothing more to replace in this line. | |
5239 * 1. Handle match with empty string. | |
5240 * 2. If do_ask is set, ask for confirmation. | |
5241 * 3. substitute the string. | |
5242 * 4. if do_all is set, find next match | |
5243 * 5. break if there isn't another match in this line | |
5244 */ | |
5245 for (;;) | |
5246 { | |
1499 | 5247 /* Advance "lnum" to the line where the match starts. The |
5248 * match does not start in the first line when there is a line | |
5249 * break before \zs. */ | |
5250 if (regmatch.startpos[0].lnum > 0) | |
5251 { | |
5252 lnum += regmatch.startpos[0].lnum; | |
5253 sub_firstlnum += regmatch.startpos[0].lnum; | |
5254 nmatch -= regmatch.startpos[0].lnum; | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5255 VIM_CLEAR(sub_firstline); |
1499 | 5256 } |
5257 | |
5258 if (sub_firstline == NULL) | |
5259 { | |
5260 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5261 if (sub_firstline == NULL) | |
5262 { | |
5263 vim_free(new_start); | |
5264 goto outofmem; | |
5265 } | |
5266 } | |
5267 | |
7 | 5268 /* Save the line number of the last change for the final |
5269 * cursor position (just like Vi). */ | |
5270 curwin->w_cursor.lnum = lnum; | |
5271 do_again = FALSE; | |
5272 | |
5273 /* | |
5274 * 1. Match empty string does not count, except for first | |
5275 * match. This reproduces the strange vi behaviour. | |
5276 * This also catches endless loops. | |
5277 */ | |
5278 if (matchcol == prev_matchcol | |
5279 && regmatch.endpos[0].lnum == 0 | |
5280 && matchcol == regmatch.endpos[0].col) | |
5281 { | |
15 | 5282 if (sub_firstline[matchcol] == NUL) |
5283 /* We already were at the end of the line. Don't look | |
5284 * for a match in this line again. */ | |
5285 skip_match = TRUE; | |
5286 else | |
2837 | 5287 { |
5288 /* search for a match at next column */ | |
5289 #ifdef FEAT_MBYTE | |
5290 if (has_mbyte) | |
5291 matchcol += mb_ptr2len(sub_firstline + matchcol); | |
5292 else | |
5293 #endif | |
5294 ++matchcol; | |
5295 } | |
7 | 5296 goto skip; |
5297 } | |
5298 | |
5299 /* Normally we continue searching for a match just after the | |
5300 * previous match. */ | |
5301 matchcol = regmatch.endpos[0].col; | |
5302 prev_matchcol = matchcol; | |
5303 | |
5304 /* | |
170 | 5305 * 2. If do_count is set only increase the counter. |
5306 * If do_ask is set, ask for confirmation. | |
7 | 5307 */ |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5308 if (subflags.do_count) |
170 | 5309 { |
5310 /* For a multi-line match, put matchcol at the NUL at | |
5311 * the end of the line and set nmatch to one, so that | |
5312 * we continue looking for a match on the next line. | |
5313 * Avoids that ":s/\nB\@=//gc" get stuck. */ | |
5314 if (nmatch > 1) | |
5315 { | |
835 | 5316 matchcol = (colnr_T)STRLEN(sub_firstline); |
170 | 5317 nmatch = 1; |
1483 | 5318 skip_match = TRUE; |
170 | 5319 } |
5320 sub_nsubs++; | |
5321 did_sub = TRUE; | |
3736 | 5322 #ifdef FEAT_EVAL |
5323 /* Skip the substitution, unless an expression is used, | |
5324 * then it is evaluated in the sandbox. */ | |
5325 if (!(sub[0] == '\\' && sub[1] == '=')) | |
5326 #endif | |
5327 goto skip; | |
170 | 5328 } |
5329 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5330 if (subflags.do_ask) |
7 | 5331 { |
1874 | 5332 int typed = 0; |
1872 | 5333 |
7 | 5334 /* change State to CONFIRM, so that the mouse works |
5335 * properly */ | |
5336 save_State = State; | |
5337 State = CONFIRM; | |
5338 #ifdef FEAT_MOUSE | |
5339 setmouse(); /* disable mouse in xterm */ | |
5340 #endif | |
5341 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
|
5342 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
|
5343 do_check_cursorbind(); |
7 | 5344 |
5345 /* When 'cpoptions' contains "u" don't sync undo when | |
5346 * asking for confirmation. */ | |
5347 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5348 ++no_u_sync; | |
5349 | |
5350 /* | |
5351 * Loop until 'y', 'n', 'q', CTRL-E or CTRL-Y typed. | |
5352 */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5353 while (subflags.do_ask) |
7 | 5354 { |
169 | 5355 if (exmode_active) |
5356 { | |
5357 char_u *resp; | |
5358 colnr_T sc, ec; | |
5359 | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5360 print_line_no_prefix(lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5361 subflags.do_number, subflags.do_list); |
169 | 5362 |
5363 getvcol(curwin, &curwin->w_cursor, &sc, NULL, NULL); | |
5364 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
|
5365 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
|
5366 curwin->w_cursor.col = 0; |
169 | 5367 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
|
5368 if (subflags.do_number || curwin->w_p_nu) |
5396 | 5369 { |
5370 int numw = number_width(curwin) + 1; | |
5371 sc += numw; | |
5372 ec += numw; | |
5373 } | |
169 | 5374 msg_start(); |
170 | 5375 for (i = 0; i < (long)sc; ++i) |
169 | 5376 msg_putchar(' '); |
170 | 5377 for ( ; i <= (long)ec; ++i) |
169 | 5378 msg_putchar('^'); |
5379 | |
5380 resp = getexmodeline('?', NULL, 0); | |
5381 if (resp != NULL) | |
5382 { | |
1872 | 5383 typed = *resp; |
169 | 5384 vim_free(resp); |
5385 } | |
5386 } | |
5387 else | |
5388 { | |
4076 | 5389 char_u *orig_line = NULL; |
5390 int len_change = 0; | |
7 | 5391 #ifdef FEAT_FOLDING |
169 | 5392 int save_p_fen = curwin->w_p_fen; |
5393 | |
5394 curwin->w_p_fen = FALSE; | |
5395 #endif | |
5396 /* Invert the matched string. | |
5397 * Remove the inversion afterwards. */ | |
5398 temp = RedrawingDisabled; | |
5399 RedrawingDisabled = 0; | |
5400 | |
4076 | 5401 if (new_start != NULL) |
5402 { | |
5403 /* There already was a substitution, we would | |
5404 * like to show this to the user. We cannot | |
5405 * really update the line, it would change | |
5406 * what matches. Temporarily replace the line | |
5407 * and change it back afterwards. */ | |
5408 orig_line = vim_strsave(ml_get(lnum)); | |
5409 if (orig_line != NULL) | |
5410 { | |
5411 char_u *new_line = concat_str(new_start, | |
5412 sub_firstline + copycol); | |
5413 | |
5414 if (new_line == NULL) | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5415 VIM_CLEAR(orig_line); |
4076 | 5416 else |
5417 { | |
5418 /* Position the cursor relative to the | |
5419 * end of the line, the previous | |
5420 * substitute may have inserted or | |
5421 * deleted characters before the | |
5422 * cursor. */ | |
4086 | 5423 len_change = (int)STRLEN(new_line) |
5424 - (int)STRLEN(orig_line); | |
4076 | 5425 curwin->w_cursor.col += len_change; |
5426 ml_replace(lnum, new_line, FALSE); | |
5427 } | |
5428 } | |
5429 } | |
5430 | |
1499 | 5431 search_match_lines = regmatch.endpos[0].lnum |
5432 - regmatch.startpos[0].lnum; | |
4076 | 5433 search_match_endcol = regmatch.endpos[0].col |
5434 + len_change; | |
169 | 5435 highlight_match = TRUE; |
5436 | |
5437 update_topline(); | |
5438 validate_cursor(); | |
748 | 5439 update_screen(SOME_VALID); |
169 | 5440 highlight_match = FALSE; |
748 | 5441 redraw_later(SOME_VALID); |
7 | 5442 |
5443 #ifdef FEAT_FOLDING | |
169 | 5444 curwin->w_p_fen = save_p_fen; |
5445 #endif | |
5446 if (msg_row == Rows - 1) | |
5447 msg_didout = FALSE; /* avoid a scroll-up */ | |
5448 msg_starthere(); | |
5449 i = msg_scroll; | |
5450 msg_scroll = 0; /* truncate msg when | |
5451 needed */ | |
5452 msg_no_more = TRUE; | |
5453 /* write message same highlighting as for | |
5454 * wait_return */ | |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
5455 smsg_attr(HL_ATTR(HLF_R), |
169 | 5456 (char_u *)_("replace with %s (y/n/a/q/l/^E/^Y)?"), sub); |
5457 msg_no_more = FALSE; | |
5458 msg_scroll = i; | |
5459 showruler(TRUE); | |
5460 windgoto(msg_row, msg_col); | |
5461 RedrawingDisabled = temp; | |
7 | 5462 |
5463 #ifdef USE_ON_FLY_SCROLL | |
169 | 5464 dont_scroll = FALSE; /* allow scrolling here */ |
5465 #endif | |
5466 ++no_mapping; /* don't map this key */ | |
5467 ++allow_keys; /* allow special keys */ | |
1872 | 5468 typed = plain_vgetc(); |
169 | 5469 --allow_keys; |
5470 --no_mapping; | |
5471 | |
5472 /* clear the question */ | |
5473 msg_didout = FALSE; /* don't scroll up */ | |
5474 msg_col = 0; | |
5475 gotocmdline(TRUE); | |
4076 | 5476 |
5477 /* restore the line */ | |
5478 if (orig_line != NULL) | |
5479 ml_replace(lnum, orig_line, FALSE); | |
169 | 5480 } |
5481 | |
7 | 5482 need_wait_return = FALSE; /* no hit-return prompt */ |
1872 | 5483 if (typed == 'q' || typed == ESC || typed == Ctrl_C |
7 | 5484 #ifdef UNIX |
1872 | 5485 || typed == intr_char |
7 | 5486 #endif |
5487 ) | |
5488 { | |
5489 got_quit = TRUE; | |
5490 break; | |
5491 } | |
1872 | 5492 if (typed == 'n') |
7 | 5493 break; |
1872 | 5494 if (typed == 'y') |
7 | 5495 break; |
1872 | 5496 if (typed == 'l') |
7 | 5497 { |
5498 /* last: replace and then stop */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5499 subflags.do_all = FALSE; |
7 | 5500 line2 = lnum; |
5501 break; | |
5502 } | |
1872 | 5503 if (typed == 'a') |
7 | 5504 { |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5505 subflags.do_ask = FALSE; |
7 | 5506 break; |
5507 } | |
5508 #ifdef FEAT_INS_EXPAND | |
1872 | 5509 if (typed == Ctrl_E) |
7 | 5510 scrollup_clamp(); |
1872 | 5511 else if (typed == Ctrl_Y) |
7 | 5512 scrolldown_clamp(); |
5513 #endif | |
5514 } | |
5515 State = save_State; | |
5516 #ifdef FEAT_MOUSE | |
5517 setmouse(); | |
5518 #endif | |
5519 if (vim_strchr(p_cpo, CPO_UNDO) != NULL) | |
5520 --no_u_sync; | |
5521 | |
1872 | 5522 if (typed == 'n') |
7 | 5523 { |
5524 /* For a multi-line match, put matchcol at the NUL at | |
5525 * the end of the line and set nmatch to one, so that | |
5526 * we continue looking for a match on the next line. | |
1091 | 5527 * Avoids that ":%s/\nB\@=//gc" and ":%s/\n/,\r/gc" |
5528 * get stuck when pressing 'n'. */ | |
7 | 5529 if (nmatch > 1) |
5530 { | |
835 | 5531 matchcol = (colnr_T)STRLEN(sub_firstline); |
1091 | 5532 skip_match = TRUE; |
7 | 5533 } |
5534 goto skip; | |
5535 } | |
5536 if (got_quit) | |
4099 | 5537 goto skip; |
7 | 5538 } |
5539 | |
5540 /* Move the cursor to the start of the match, so that we can | |
5541 * use "\=col("."). */ | |
5542 curwin->w_cursor.col = regmatch.startpos[0].col; | |
5543 | |
5544 /* | |
5545 * 3. substitute the string. | |
5546 */ | |
3736 | 5547 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5548 if (subflags.do_count) |
3736 | 5549 { |
3786 | 5550 /* prevent accidentally changing the buffer by a function */ |
3736 | 5551 save_ma = curbuf->b_p_ma; |
5552 curbuf->b_p_ma = FALSE; | |
5553 sandbox++; | |
5554 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5555 /* 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
|
5556 * :s/^/\=execute("s#^##gn") */ |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5557 subflags_save = subflags; |
3736 | 5558 #endif |
7 | 5559 /* get length of substitution part */ |
1499 | 5560 sublen = vim_regsub_multi(®match, |
5561 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5562 sub, sub_firstline, FALSE, p_magic, TRUE); |
3736 | 5563 #ifdef FEAT_EVAL |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5564 /* 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
|
5565 subflags = subflags_save; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5566 if (subflags.do_count) |
3736 | 5567 { |
5568 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
|
5569 if (sandbox > 0) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5570 sandbox--; |
3736 | 5571 goto skip; |
5572 } | |
5573 #endif | |
7 | 5574 |
533 | 5575 /* When the match included the "$" of the last line it may |
819 | 5576 * go beyond the last line of the buffer. */ |
533 | 5577 if (nmatch > curbuf->b_ml.ml_line_count - sub_firstlnum + 1) |
5578 { | |
5579 nmatch = curbuf->b_ml.ml_line_count - sub_firstlnum + 1; | |
5580 skip_match = TRUE; | |
5581 } | |
5582 | |
7 | 5583 /* Need room for: |
5584 * - result so far in new_start (not for first sub in line) | |
5585 * - original text up to match | |
5586 * - length of substituted part | |
5587 * - original text after match | |
5588 */ | |
5589 if (nmatch == 1) | |
5590 p1 = sub_firstline; | |
5591 else | |
5592 { | |
5593 p1 = ml_get(sub_firstlnum + nmatch - 1); | |
5594 nmatch_tl += nmatch - 1; | |
5595 } | |
1872 | 5596 copy_len = regmatch.startpos[0].col - copycol; |
5597 needed_len = copy_len + ((unsigned)STRLEN(p1) | |
5598 - regmatch.endpos[0].col) + sublen + 1; | |
7 | 5599 if (new_start == NULL) |
5600 { | |
5601 /* | |
5602 * Get some space for a temporary buffer to do the | |
5603 * substitution into (and some extra space to avoid | |
5604 * too many calls to alloc()/free()). | |
5605 */ | |
5606 new_start_len = needed_len + 50; | |
5607 if ((new_start = alloc_check(new_start_len)) == NULL) | |
5608 goto outofmem; | |
5609 *new_start = NUL; | |
5610 new_end = new_start; | |
5611 } | |
5612 else | |
5613 { | |
5614 /* | |
5615 * Check if the temporary buffer is long enough to do the | |
5616 * substitution into. If not, make it larger (with a bit | |
5617 * extra to avoid too many calls to alloc()/free()). | |
5618 */ | |
5619 len = (unsigned)STRLEN(new_start); | |
5620 needed_len += len; | |
1872 | 5621 if (needed_len > (int)new_start_len) |
7 | 5622 { |
5623 new_start_len = needed_len + 50; | |
5624 if ((p1 = alloc_check(new_start_len)) == NULL) | |
5625 { | |
5626 vim_free(new_start); | |
5627 goto outofmem; | |
5628 } | |
5629 mch_memmove(p1, new_start, (size_t)(len + 1)); | |
5630 vim_free(new_start); | |
5631 new_start = p1; | |
5632 } | |
5633 new_end = new_start + len; | |
5634 } | |
5635 | |
5636 /* | |
5637 * copy the text up to the part that matched | |
5638 */ | |
1872 | 5639 mch_memmove(new_end, sub_firstline + copycol, (size_t)copy_len); |
5640 new_end += copy_len; | |
7 | 5641 |
1499 | 5642 (void)vim_regsub_multi(®match, |
5643 sub_firstlnum - regmatch.startpos[0].lnum, | |
7 | 5644 sub, new_end, TRUE, p_magic, TRUE); |
5645 sub_nsubs++; | |
5646 did_sub = TRUE; | |
5647 | |
5648 /* Move the cursor to the start of the line, to avoid that it | |
5649 * is beyond the end of the line after the substitution. */ | |
5650 curwin->w_cursor.col = 0; | |
5651 | |
5652 /* For a multi-line match, make a copy of the last matched | |
5653 * line and continue in that one. */ | |
5654 if (nmatch > 1) | |
5655 { | |
5656 sub_firstlnum += nmatch - 1; | |
5657 vim_free(sub_firstline); | |
5658 sub_firstline = vim_strsave(ml_get(sub_firstlnum)); | |
5659 /* When going beyond the last line, stop substituting. */ | |
5660 if (sub_firstlnum <= line2) | |
5661 do_again = TRUE; | |
5662 else | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5663 subflags.do_all = FALSE; |
7 | 5664 } |
5665 | |
5666 /* Remember next character to be copied. */ | |
5667 copycol = regmatch.endpos[0].col; | |
5668 | |
819 | 5669 if (skip_match) |
5670 { | |
5671 /* Already hit end of the buffer, sub_firstlnum is one | |
5672 * less than what it ought to be. */ | |
5673 vim_free(sub_firstline); | |
5674 sub_firstline = vim_strsave((char_u *)""); | |
5675 copycol = 0; | |
5676 } | |
5677 | |
7 | 5678 /* |
5679 * Now the trick is to replace CTRL-M chars with a real line | |
5680 * break. This would make it impossible to insert a CTRL-M in | |
5681 * the text. The line break can be avoided by preceding the | |
5682 * CTRL-M with a backslash. To be able to insert a backslash, | |
5683 * they must be doubled in the string and are halved here. | |
5684 * That is Vi compatible. | |
5685 */ | |
5686 for (p1 = new_end; *p1; ++p1) | |
5687 { | |
5688 if (p1[0] == '\\' && p1[1] != NUL) /* remove backslash */ | |
1624 | 5689 STRMOVE(p1, p1 + 1); |
7 | 5690 else if (*p1 == CAR) |
5691 { | |
5692 if (u_inssub(lnum) == OK) /* prepare for undo */ | |
5693 { | |
5694 *p1 = NUL; /* truncate up to the CR */ | |
5695 ml_append(lnum - 1, new_start, | |
5696 (colnr_T)(p1 - new_start + 1), FALSE); | |
5697 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
|
5698 if (subflags.do_ask) |
7 | 5699 appended_lines(lnum - 1, 1L); |
5700 else | |
5701 { | |
5702 if (first_line == 0) | |
5703 first_line = lnum; | |
5704 last_line = lnum + 1; | |
5705 } | |
5706 /* All line numbers increase. */ | |
5707 ++sub_firstlnum; | |
5708 ++lnum; | |
5709 ++line2; | |
5710 /* move the cursor to the new line, like Vi */ | |
5711 ++curwin->w_cursor.lnum; | |
1444 | 5712 /* copy the rest */ |
1624 | 5713 STRMOVE(new_start, p1 + 1); |
7 | 5714 p1 = new_start - 1; |
5715 } | |
5716 } | |
5717 #ifdef FEAT_MBYTE | |
5718 else if (has_mbyte) | |
474 | 5719 p1 += (*mb_ptr2len)(p1) - 1; |
7 | 5720 #endif |
5721 } | |
5722 | |
5723 /* | |
5724 * 4. If do_all is set, find next match. | |
5725 * Prevent endless loop with patterns that match empty | |
5726 * strings, e.g. :s/$/pat/g or :s/[a-z]* /(&)/g. | |
5727 * But ":s/\n/#/" is OK. | |
5728 */ | |
5729 skip: | |
5730 /* We already know that we did the last subst when we are at | |
5731 * the end of the line, except that a pattern like | |
1499 | 5732 * "bar\|\nfoo" may match at the NUL. "lnum" can be below |
5733 * "line2" when there is a \zs in the pattern after a line | |
5734 * break. */ | |
15 | 5735 lastone = (skip_match |
5736 || got_int | |
5737 || got_quit | |
1499 | 5738 || lnum > line2 |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5739 || !(subflags.do_all || do_again) |
15 | 5740 || (sub_firstline[matchcol] == NUL && nmatch <= 1 |
5741 && !re_multiline(regmatch.regprog))); | |
7 | 5742 nmatch = -1; |
5743 | |
5744 /* | |
5745 * Replace the line in the buffer when needed. This is | |
5746 * skipped when there are more matches. | |
5747 * The check for nmatch_tl is needed for when multi-line | |
5748 * matching must replace the lines before trying to do another | |
5749 * match, otherwise "\@<=" won't work. | |
1499 | 5750 * When the match starts below where we start searching also |
5751 * need to replace the line first (using \zs after \n). | |
7 | 5752 */ |
5753 if (lastone | |
5754 || nmatch_tl > 0 | |
5755 || (nmatch = vim_regexec_multi(®match, curwin, | |
1521 | 5756 curbuf, sub_firstlnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5757 matchcol, NULL, NULL)) == 0 |
1499 | 5758 || regmatch.startpos[0].lnum > 0) |
7 | 5759 { |
5760 if (new_start != NULL) | |
5761 { | |
5762 /* | |
5763 * Copy the rest of the line, that didn't match. | |
5764 * "matchcol" has to be adjusted, we use the end of | |
5765 * the line as reference, because the substitute may | |
5766 * have changed the number of characters. Same for | |
5767 * "prev_matchcol". | |
5768 */ | |
5769 STRCAT(new_start, sub_firstline + copycol); | |
5770 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5771 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5772 - prev_matchcol; | |
5773 | |
5774 if (u_savesub(lnum) != OK) | |
5775 break; | |
5776 ml_replace(lnum, new_start, TRUE); | |
5777 | |
5778 if (nmatch_tl > 0) | |
5779 { | |
5780 /* | |
5781 * Matched lines have now been substituted and are | |
5782 * useless, delete them. The part after the match | |
5783 * has been appended to new_start, we don't need | |
5784 * it in the buffer. | |
5785 */ | |
5786 ++lnum; | |
5787 if (u_savedel(lnum, nmatch_tl) != OK) | |
5788 break; | |
5789 for (i = 0; i < nmatch_tl; ++i) | |
5790 ml_delete(lnum, (int)FALSE); | |
5791 mark_adjust(lnum, lnum + nmatch_tl - 1, | |
5792 (long)MAXLNUM, -nmatch_tl); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5793 if (subflags.do_ask) |
7 | 5794 deleted_lines(lnum, nmatch_tl); |
5795 --lnum; | |
5796 line2 -= nmatch_tl; /* nr of lines decreases */ | |
5797 nmatch_tl = 0; | |
5798 } | |
5799 | |
5800 /* When asking, undo is saved each time, must also set | |
5801 * changed flag each time. */ | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5802 if (subflags.do_ask) |
7 | 5803 changed_bytes(lnum, 0); |
5804 else | |
5805 { | |
5806 if (first_line == 0) | |
5807 first_line = lnum; | |
5808 last_line = lnum + 1; | |
5809 } | |
5810 | |
5811 sub_firstlnum = lnum; | |
5812 vim_free(sub_firstline); /* free the temp buffer */ | |
5813 sub_firstline = new_start; | |
5814 new_start = NULL; | |
5815 matchcol = (colnr_T)STRLEN(sub_firstline) - matchcol; | |
5816 prev_matchcol = (colnr_T)STRLEN(sub_firstline) | |
5817 - prev_matchcol; | |
5818 copycol = 0; | |
5819 } | |
5820 if (nmatch == -1 && !lastone) | |
5821 nmatch = vim_regexec_multi(®match, curwin, curbuf, | |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
5822 sub_firstlnum, matchcol, NULL, NULL); |
7 | 5823 |
5824 /* | |
5825 * 5. break if there isn't another match in this line | |
5826 */ | |
5827 if (nmatch <= 0) | |
1499 | 5828 { |
5829 /* If the match found didn't start where we were | |
5830 * searching, do the next search in the line where we | |
5831 * found the match. */ | |
5832 if (nmatch == -1) | |
5833 lnum -= regmatch.startpos[0].lnum; | |
7 | 5834 break; |
1499 | 5835 } |
7 | 5836 } |
5837 | |
5838 line_breakcheck(); | |
5839 } | |
5840 | |
5841 if (did_sub) | |
5842 ++sub_nlines; | |
1720 | 5843 vim_free(new_start); /* for when substitute was cancelled */ |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
5844 VIM_CLEAR(sub_firstline); /* free the copy of the original line */ |
7 | 5845 } |
5846 | |
5847 line_breakcheck(); | |
5848 } | |
5849 | |
5850 if (first_line != 0) | |
5851 { | |
5852 /* Need to subtract the number of added lines from "last_line" to get | |
5853 * the line number before the change (same as adding the number of | |
5854 * deleted lines). */ | |
5855 i = curbuf->b_ml.ml_line_count - old_line_count; | |
5856 changed_lines(first_line, 0, last_line - i, i); | |
5857 } | |
5858 | |
5859 outofmem: | |
5860 vim_free(sub_firstline); /* may have to free allocated copy of the line */ | |
170 | 5861 |
5862 /* ":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
|
5863 if (subflags.do_count) |
170 | 5864 curwin->w_cursor = old_cursor; |
5865 | |
2126
e038754d419a
updated for version 7.2.408
Bram Moolenaar <bram@zimbu.org>
parents:
1929
diff
changeset
|
5866 if (sub_nsubs > start_nsubs) |
7 | 5867 { |
5868 /* Set the '[ and '] marks. */ | |
5869 curbuf->b_op_start.lnum = eap->line1; | |
5870 curbuf->b_op_end.lnum = line2; | |
5871 curbuf->b_op_start.col = curbuf->b_op_end.col = 0; | |
5872 | |
5873 if (!global_busy) | |
5874 { | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5875 /* 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
|
5876 if (!subflags.do_ask) |
3394 | 5877 { |
5878 if (endcolumn) | |
5879 coladvance((colnr_T)MAXCOL); | |
5880 else | |
5881 beginline(BL_WHITE | BL_FIX); | |
5882 } | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5883 if (!do_sub_msg(subflags.do_count) && subflags.do_ask) |
7 | 5884 MSG(""); |
5885 } | |
5886 else | |
5887 global_need_beginline = TRUE; | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5888 if (subflags.do_print) |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5889 print_line(curwin->w_cursor.lnum, |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5890 subflags.do_number, subflags.do_list); |
7 | 5891 } |
5892 else if (!global_busy) | |
5893 { | |
5894 if (got_int) /* interrupted */ | |
5895 EMSG(_(e_interr)); | |
5896 else if (got_match) /* did find something but nothing substituted */ | |
5897 MSG(""); | |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5898 else if (subflags.do_error) /* nothing found */ |
7 | 5899 EMSG2(_(e_patnotf2), get_search_pat()); |
5900 } | |
5901 | |
4035 | 5902 #ifdef FEAT_FOLDING |
9890
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5903 if (subflags.do_ask && hasAnyFolding(curwin)) |
4035 | 5904 /* Cursor position may require updating */ |
5905 changed_window_setting(); | |
5906 #endif | |
5907 | |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
5908 vim_regfree(regmatch.regprog); |
6789 | 5909 |
5910 /* 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
|
5911 subflags.do_all = save_do_all; |
064effd222a3
commit https://github.com/vim/vim/commit/f5a39447a8ebe162ee62caa2ee502cd0e65eecaa
Christian Brabandt <cb@256bit.org>
parents:
9715
diff
changeset
|
5912 subflags.do_ask = save_do_ask; |
7 | 5913 } |
5914 | |
5915 /* | |
5916 * Give message for number of substitutions. | |
5917 * Can also be used after a ":global" command. | |
5918 * Return TRUE if a message was given. | |
5919 */ | |
484 | 5920 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5921 do_sub_msg( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5922 int count_only) /* used 'n' flag for ":s" */ |
7 | 5923 { |
5924 /* | |
5925 * Only report substitutions when: | |
5926 * - more than 'report' substitutions | |
5927 * - command was typed by user, or number of changed lines > 'report' | |
5928 * - giving messages is not disabled by 'lazyredraw' | |
5929 */ | |
170 | 5930 if (((sub_nsubs > p_report && (KeyTyped || sub_nlines > 1 || p_report < 1)) |
5931 || count_only) | |
7 | 5932 && messaging()) |
5933 { | |
5934 if (got_int) | |
5935 STRCPY(msg_buf, _("(Interrupted) ")); | |
2290
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5936 else |
22529abcd646
Fixed ":s" message. Docs updates.
Bram Moolenaar <bram@vim.org>
parents:
2280
diff
changeset
|
5937 *msg_buf = NUL; |
7 | 5938 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
|
5939 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5940 "%s", count_only ? _("1 match") : _("1 substitution")); |
7 | 5941 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5942 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
170 | 5943 count_only ? _("%ld matches") : _("%ld substitutions"), |
7 | 5944 sub_nsubs); |
5945 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
|
5946 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5947 "%s", _(" on 1 line")); |
7 | 5948 else |
2280
941ff1cd317a
Add file save counter to undo information. Add undotree() function.
Bram Moolenaar <bram@vim.org>
parents:
2254
diff
changeset
|
5949 vim_snprintf_add((char *)msg_buf, sizeof(msg_buf), |
274 | 5950 _(" on %ld lines"), (long)sub_nlines); |
7 | 5951 if (msg(msg_buf)) |
5952 /* save message to display it after redraw */ | |
680 | 5953 set_keep_msg(msg_buf, 0); |
7 | 5954 return TRUE; |
5955 } | |
5956 if (got_int) | |
5957 { | |
5958 EMSG(_(e_interr)); | |
5959 return TRUE; | |
5960 } | |
5961 return FALSE; | |
5962 } | |
5963 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5964 static void |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5965 global_exe_one(char_u *cmd, linenr_T lnum) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5966 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5967 curwin->w_cursor.lnum = lnum; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5968 curwin->w_cursor.col = 0; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5969 if (*cmd == NUL || *cmd == '\n') |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5970 do_cmdline((char_u *)"p", NULL, NULL, DOCMD_NOWAIT); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5971 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5972 do_cmdline(cmd, NULL, NULL, DOCMD_NOWAIT); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5973 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
5974 |
7 | 5975 /* |
5976 * Execute a global command of the form: | |
5977 * | |
5978 * g/pattern/X : execute X on all lines where pattern matches | |
5979 * v/pattern/X : execute X on all lines where pattern does not match | |
5980 * | |
5981 * where 'X' is an EX command | |
5982 * | |
5983 * The command character (as well as the trailing slash) is optional, and | |
5984 * is assumed to be 'p' if missing. | |
5985 * | |
5986 * This is implemented in two passes: first we scan the file for the pattern and | |
3786 | 5987 * set a mark for each line that (not) matches. Secondly we execute the command |
7 | 5988 * for each line that has a mark. This is required because after deleting |
5989 * lines we do not know where to search for the next match. | |
5990 */ | |
5991 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
5992 ex_global(exarg_T *eap) |
7 | 5993 { |
5994 linenr_T lnum; /* line number according to old situation */ | |
170 | 5995 int ndone = 0; |
7 | 5996 int type; /* first char of cmd: 'v' or 'g' */ |
5997 char_u *cmd; /* command argument */ | |
5998 | |
5999 char_u delim; /* delimiter, normally '/' */ | |
6000 char_u *pat; | |
6001 regmmatch_T regmatch; | |
6002 int match; | |
6003 int which_pat; | |
6004 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6005 /* When nesting the command works on one line. This allows for |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6006 * ":g/found/v/notfound/command". */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6007 if (global_busy && (eap->line1 != 1 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6008 || eap->line2 != curbuf->b_ml.ml_line_count)) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6009 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6010 /* will increment global_busy to break out of the loop */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6011 EMSG(_("E147: Cannot do :global recursive with a range")); |
7 | 6012 return; |
6013 } | |
6014 | |
6015 if (eap->forceit) /* ":global!" is like ":vglobal" */ | |
6016 type = 'v'; | |
6017 else | |
6018 type = *eap->cmd; | |
6019 cmd = eap->arg; | |
6020 which_pat = RE_LAST; /* default: use last used regexp */ | |
6021 | |
6022 /* | |
6023 * undocumented vi feature: | |
6024 * "\/" and "\?": use previous search pattern. | |
6025 * "\&": use previous substitute pattern. | |
6026 */ | |
6027 if (*cmd == '\\') | |
6028 { | |
6029 ++cmd; | |
6030 if (vim_strchr((char_u *)"/?&", *cmd) == NULL) | |
6031 { | |
6032 EMSG(_(e_backslash)); | |
6033 return; | |
6034 } | |
6035 if (*cmd == '&') | |
6036 which_pat = RE_SUBST; /* use previous substitute pattern */ | |
6037 else | |
6038 which_pat = RE_SEARCH; /* use previous search pattern */ | |
6039 ++cmd; | |
6040 pat = (char_u *)""; | |
6041 } | |
6042 else if (*cmd == NUL) | |
6043 { | |
6044 EMSG(_("E148: Regular expression missing from global")); | |
6045 return; | |
6046 } | |
6047 else | |
6048 { | |
6049 delim = *cmd; /* get the delimiter */ | |
6050 if (delim) | |
6051 ++cmd; /* skip delimiter if there is one */ | |
6052 pat = cmd; /* remember start of pattern */ | |
6053 cmd = skip_regexp(cmd, delim, p_magic, &eap->arg); | |
6054 if (cmd[0] == delim) /* end delimiter found */ | |
6055 *cmd++ = NUL; /* replace it with a NUL */ | |
6056 } | |
6057 | |
6058 #ifdef FEAT_FKMAP /* when in Farsi mode, reverse the character flow */ | |
6059 if (p_altkeymap && curwin->w_p_rl) | |
6060 lrFswap(pat,0); | |
6061 #endif | |
6062 | |
6063 if (search_regcomp(pat, RE_BOTH, which_pat, SEARCH_HIS, ®match) == FAIL) | |
6064 { | |
6065 EMSG(_(e_invcmd)); | |
6066 return; | |
6067 } | |
6068 | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6069 if (global_busy) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6070 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6071 lnum = curwin->w_cursor.lnum; |
1521 | 6072 match = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
6073 (colnr_T)0, NULL, NULL); |
7 | 6074 if ((type == 'g' && match) || (type == 'v' && !match)) |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6075 global_exe_one(cmd, lnum); |
7 | 6076 } |
6077 else | |
6116 | 6078 { |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6079 /* |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6080 * pass 1: set marks for each (not) matching line |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6081 */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6082 for (lnum = eap->line1; lnum <= eap->line2 && !got_int; ++lnum) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6083 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6084 /* a match on this line? */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6085 match = vim_regexec_multi(®match, curwin, curbuf, lnum, |
11521
578df034735d
patch 8.0.0643: when a pattern search is slow Vim becomes unusable
Christian Brabandt <cb@256bit.org>
parents:
11494
diff
changeset
|
6086 (colnr_T)0, NULL, NULL); |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6087 if ((type == 'g' && match) || (type == 'v' && !match)) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6088 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6089 ml_setmarked(lnum); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6090 ndone++; |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6091 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6092 line_breakcheck(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6093 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6094 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6095 /* |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6096 * pass 2: execute the command for each line that has been marked |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6097 */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6098 if (got_int) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6099 MSG(_(e_interr)); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6100 else if (ndone == 0) |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6101 { |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6102 if (type == 'v') |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6103 smsg((char_u *)_("Pattern found in every line: %s"), pat); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6104 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6105 smsg((char_u *)_("Pattern not found: %s"), pat); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6106 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6107 else |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6108 { |
6116 | 6109 #ifdef FEAT_CLIPBOARD |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6110 start_global_changes(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6111 #endif |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6112 global_exe(cmd); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6113 #ifdef FEAT_CLIPBOARD |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6114 end_global_changes(); |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6115 #endif |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6116 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6117 |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6118 ml_clearmarked(); /* clear rest of the marks */ |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6119 } |
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6120 |
4805
66803af09906
updated for version 7.3.1149
Bram Moolenaar <bram@vim.org>
parents:
4613
diff
changeset
|
6121 vim_regfree(regmatch.regprog); |
7 | 6122 } |
6123 | |
6124 /* | |
6125 * Execute "cmd" on lines marked with ml_setmarked(). | |
6126 */ | |
6127 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6128 global_exe(char_u *cmd) |
7 | 6129 { |
2819 | 6130 linenr_T old_lcount; /* b_ml.ml_line_count before the command */ |
6131 buf_T *old_buf = curbuf; /* remember what buffer we started in */ | |
6132 linenr_T lnum; /* line number according to old situation */ | |
7 | 6133 |
6134 /* | |
6135 * Set current position only once for a global command. | |
6136 * If global_busy is set, setpcmark() will not do anything. | |
6137 * If there is an error, global_busy will be incremented. | |
6138 */ | |
6139 setpcmark(); | |
6140 | |
6141 /* When the command writes a message, don't overwrite the command. */ | |
6142 msg_didout = TRUE; | |
6143 | |
2127
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6144 sub_nsubs = 0; |
4e22214f8464
updated for version 7.2.409
Bram Moolenaar <bram@zimbu.org>
parents:
2126
diff
changeset
|
6145 sub_nlines = 0; |
7 | 6146 global_need_beginline = FALSE; |
6147 global_busy = 1; | |
6148 old_lcount = curbuf->b_ml.ml_line_count; | |
6149 while (!got_int && (lnum = ml_firstmarked()) != 0 && global_busy == 1) | |
6150 { | |
11494
8e5ec22db3d8
patch 8.0.0630: it is not easy to work on lines without a match
Christian Brabandt <cb@256bit.org>
parents:
11476
diff
changeset
|
6151 global_exe_one(cmd, lnum); |
7 | 6152 ui_breakcheck(); |
6153 } | |
6154 | |
6155 global_busy = 0; | |
6156 if (global_need_beginline) | |
6157 beginline(BL_WHITE | BL_FIX); | |
6158 else | |
6159 check_cursor(); /* cursor may be beyond the end of the line */ | |
6160 | |
39 | 6161 /* the cursor may not have moved in the text but a change in a previous |
6162 * line may move it on the screen */ | |
6163 changed_line_abv_curs(); | |
6164 | |
7 | 6165 /* If it looks like no message was written, allow overwriting the |
6166 * command with the report for number of changes. */ | |
6167 if (msg_col == 0 && msg_scrolled == 0) | |
6168 msg_didout = FALSE; | |
6169 | |
1227 | 6170 /* If substitutes done, report number of substitutes, otherwise report |
2819 | 6171 * number of extra or deleted lines. |
6172 * Don't report extra or deleted lines in the edge case where the buffer | |
6173 * we are in after execution is different from the buffer we started in. */ | |
6174 if (!do_sub_msg(FALSE) && curbuf == old_buf) | |
7 | 6175 msgmore(curbuf->b_ml.ml_line_count - old_lcount); |
6176 } | |
6177 | |
6178 #ifdef FEAT_VIMINFO | |
6179 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6180 read_viminfo_sub_string(vir_T *virp, int force) |
7 | 6181 { |
2690 | 6182 if (force) |
7 | 6183 vim_free(old_sub); |
6184 if (force || old_sub == NULL) | |
6185 old_sub = viminfo_readstring(virp, 1, TRUE); | |
6186 return viminfo_readline(virp); | |
6187 } | |
6188 | |
6189 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6190 write_viminfo_sub_string(FILE *fp) |
7 | 6191 { |
6192 if (get_viminfo_parameter('/') != 0 && old_sub != NULL) | |
6193 { | |
2545
298d8d6e69be
Avoid warnings from the clang compiler. (Dominique Pelle)
Bram Moolenaar <bram@vim.org>
parents:
2394
diff
changeset
|
6194 fputs(_("\n# Last Substitute String:\n$"), fp); |
7 | 6195 viminfo_writestring(fp, old_sub); |
6196 } | |
6197 } | |
6198 #endif /* FEAT_VIMINFO */ | |
6199 | |
359 | 6200 #if defined(EXITFREE) || defined(PROTO) |
6201 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6202 free_old_sub(void) |
359 | 6203 { |
6204 vim_free(old_sub); | |
6205 } | |
6206 #endif | |
6207 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6208 #if defined(FEAT_QUICKFIX) || defined(PROTO) |
7 | 6209 /* |
6210 * Set up for a tagpreview. | |
735 | 6211 * Return TRUE when it was created. |
7 | 6212 */ |
735 | 6213 int |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6214 prepare_tagpreview( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6215 int undo_sync) /* sync undo when leaving the window */ |
7 | 6216 { |
6217 win_T *wp; | |
6218 | |
6219 # ifdef FEAT_GUI | |
6220 need_mouse_correct = TRUE; | |
6221 # endif | |
6222 | |
6223 /* | |
6224 * If there is already a preview window open, use that one. | |
6225 */ | |
6226 if (!curwin->w_p_pvw) | |
6227 { | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6228 FOR_ALL_WINDOWS(wp) |
7 | 6229 if (wp->w_p_pvw) |
6230 break; | |
6231 if (wp != NULL) | |
816 | 6232 win_enter(wp, undo_sync); |
7 | 6233 else |
6234 { | |
6235 /* | |
6236 * There is no preview window open yet. Create one. | |
6237 */ | |
6238 if (win_split(g_do_tagpreview > 0 ? g_do_tagpreview : 0, 0) | |
6239 == FAIL) | |
735 | 6240 return FALSE; |
7 | 6241 curwin->w_p_pvw = TRUE; |
6242 curwin->w_p_wfh = TRUE; | |
2583 | 6243 RESET_BINDING(curwin); /* don't take over 'scrollbind' |
6244 and 'cursorbind' */ | |
7 | 6245 # ifdef FEAT_DIFF |
6246 curwin->w_p_diff = FALSE; /* no 'diff' */ | |
6247 # endif | |
6248 # ifdef FEAT_FOLDING | |
6249 curwin->w_p_fdc = 0; /* no 'foldcolumn' */ | |
6250 # endif | |
735 | 6251 return TRUE; |
7 | 6252 } |
6253 } | |
735 | 6254 return FALSE; |
7 | 6255 } |
6256 | |
6257 #endif | |
6258 | |
6259 | |
6260 /* | |
6261 * ":help": open a read-only window on a help file | |
6262 */ | |
6263 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6264 ex_help(exarg_T *eap) |
7 | 6265 { |
6266 char_u *arg; | |
6267 char_u *tag; | |
6268 FILE *helpfd; /* file descriptor of help file */ | |
6269 int n; | |
6270 int i; | |
6271 win_T *wp; | |
6272 int num_matches; | |
6273 char_u **matches; | |
6274 char_u *p; | |
6275 int empty_fnum = 0; | |
6276 int alt_fnum = 0; | |
6277 buf_T *buf; | |
6278 #ifdef FEAT_MULTI_LANG | |
6279 int len; | |
9 | 6280 char_u *lang; |
7 | 6281 #endif |
3112 | 6282 #ifdef FEAT_FOLDING |
6283 int old_KeyTyped = KeyTyped; | |
6284 #endif | |
7 | 6285 |
6286 if (eap != NULL) | |
6287 { | |
6288 /* | |
6289 * A ":help" command ends at the first LF, or at a '|' that is | |
6290 * followed by some text. Set nextcmd to the following command. | |
6291 */ | |
6292 for (arg = eap->arg; *arg; ++arg) | |
6293 { | |
6294 if (*arg == '\n' || *arg == '\r' | |
6295 || (*arg == '|' && arg[1] != NUL && arg[1] != '|')) | |
6296 { | |
6297 *arg++ = NUL; | |
6298 eap->nextcmd = arg; | |
6299 break; | |
6300 } | |
6301 } | |
6302 arg = eap->arg; | |
6303 | |
3446 | 6304 if (eap->forceit && *arg == NUL && !curbuf->b_help) |
7 | 6305 { |
6306 EMSG(_("E478: Don't panic!")); | |
6307 return; | |
6308 } | |
6309 | |
6310 if (eap->skip) /* not executing commands */ | |
6311 return; | |
6312 } | |
6313 else | |
6314 arg = (char_u *)""; | |
6315 | |
6316 /* remove trailing blanks */ | |
6317 p = arg + STRLEN(arg) - 1; | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6318 while (p > arg && VIM_ISWHITE(*p) && p[-1] != '\\') |
7 | 6319 *p-- = NUL; |
6320 | |
6321 #ifdef FEAT_MULTI_LANG | |
6322 /* Check for a specified language */ | |
9 | 6323 lang = check_help_lang(arg); |
7 | 6324 #endif |
6325 | |
6326 /* When no argument given go to the index. */ | |
6327 if (*arg == NUL) | |
6328 arg = (char_u *)"help.txt"; | |
6329 | |
6330 /* | |
6331 * Check if there is a match for the argument. | |
6332 */ | |
6333 n = find_help_tags(arg, &num_matches, &matches, | |
6334 eap != NULL && eap->forceit); | |
6335 | |
6336 i = 0; | |
6337 #ifdef FEAT_MULTI_LANG | |
6338 if (n != FAIL && lang != NULL) | |
6339 /* Find first item with the requested language. */ | |
6340 for (i = 0; i < num_matches; ++i) | |
6341 { | |
835 | 6342 len = (int)STRLEN(matches[i]); |
7 | 6343 if (len > 3 && matches[i][len - 3] == '@' |
6344 && STRICMP(matches[i] + len - 2, lang) == 0) | |
6345 break; | |
6346 } | |
6347 #endif | |
6348 if (i >= num_matches || n == FAIL) | |
6349 { | |
6350 #ifdef FEAT_MULTI_LANG | |
6351 if (lang != NULL) | |
6352 EMSG3(_("E661: Sorry, no '%s' help for %s"), lang, arg); | |
6353 else | |
6354 #endif | |
6355 EMSG2(_("E149: Sorry, no help for %s"), arg); | |
6356 if (n != FAIL) | |
6357 FreeWild(num_matches, matches); | |
6358 return; | |
6359 } | |
6360 | |
6361 /* The first match (in the requested language) is the best match. */ | |
6362 tag = vim_strsave(matches[i]); | |
6363 FreeWild(num_matches, matches); | |
6364 | |
6365 #ifdef FEAT_GUI | |
6366 need_mouse_correct = TRUE; | |
6367 #endif | |
6368 | |
6369 /* | |
6370 * Re-use an existing help window or open a new one. | |
684 | 6371 * Always open a new one for ":tab help". |
7 | 6372 */ |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6373 if (!bt_help(curwin->w_buffer) || cmdmod.tab != 0) |
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6374 { |
684 | 6375 if (cmdmod.tab != 0) |
6376 wp = NULL; | |
6377 else | |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
9487
diff
changeset
|
6378 FOR_ALL_WINDOWS(wp) |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
6379 if (bt_help(wp->w_buffer)) |
684 | 6380 break; |
7 | 6381 if (wp != NULL && wp->w_buffer->b_nwindows > 0) |
6382 win_enter(wp, TRUE); | |
6383 else | |
6384 { | |
6385 /* | |
6386 * There is no help window yet. | |
6387 * Try to open the file specified by the "helpfile" option. | |
6388 */ | |
6389 if ((helpfd = mch_fopen((char *)p_hf, READBIN)) == NULL) | |
6390 { | |
274 | 6391 smsg((char_u *)_("Sorry, help file \"%s\" not found"), p_hf); |
7 | 6392 goto erret; |
6393 } | |
6394 fclose(helpfd); | |
6395 | |
6396 /* Split off help window; put it at far top if no position | |
684 | 6397 * specified, the current window is vertically split and |
6398 * narrow. */ | |
7 | 6399 n = WSP_HELP; |
6400 if (cmdmod.split == 0 && curwin->w_width != Columns | |
684 | 6401 && curwin->w_width < 80) |
7 | 6402 n |= WSP_TOP; |
6403 if (win_split(0, n) == FAIL) | |
684 | 6404 goto erret; |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6405 |
7 | 6406 if (curwin->w_height < p_hh) |
6407 win_setheight((int)p_hh); | |
6408 | |
6409 /* | |
6410 * Open help file (do_ecmd() will set b_help flag, readfile() will | |
6411 * set b_p_ro flag). | |
6412 * Set the alternate file to the previously edited file. | |
6413 */ | |
6414 alt_fnum = curbuf->b_fnum; | |
6415 (void)do_ecmd(0, NULL, NULL, NULL, ECMD_LASTL, | |
1743 | 6416 ECMD_HIDE + ECMD_SET_HELP, |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12297
diff
changeset
|
6417 NULL); /* buffer is still open, don't store info */ |
22 | 6418 if (!cmdmod.keepalt) |
6419 curwin->w_alt_fnum = alt_fnum; | |
7 | 6420 empty_fnum = curbuf->b_fnum; |
6421 } | |
6422 } | |
6423 | |
6424 if (!p_im) | |
6425 restart_edit = 0; /* don't want insert mode in help file */ | |
6426 | |
3112 | 6427 #ifdef FEAT_FOLDING |
6428 /* Restore KeyTyped, setting 'filetype=help' may reset it. | |
6429 * It is needed for do_tag top open folds under the cursor. */ | |
6430 KeyTyped = old_KeyTyped; | |
6431 #endif | |
6432 | |
7 | 6433 if (tag != NULL) |
6434 do_tag(tag, DT_HELP, 1, FALSE, TRUE); | |
6435 | |
819 | 6436 /* Delete the empty buffer if we're not using it. Careful: autocommands |
6437 * may have jumped to another window, check that the buffer is not in a | |
6438 * window. */ | |
7 | 6439 if (empty_fnum != 0 && curbuf->b_fnum != empty_fnum) |
6440 { | |
6441 buf = buflist_findnr(empty_fnum); | |
819 | 6442 if (buf != NULL && buf->b_nwindows == 0) |
7 | 6443 wipe_buffer(buf, TRUE); |
6444 } | |
6445 | |
6446 /* keep the previous alternate file */ | |
22 | 6447 if (alt_fnum != 0 && curwin->w_alt_fnum == empty_fnum && !cmdmod.keepalt) |
7 | 6448 curwin->w_alt_fnum = alt_fnum; |
6449 | |
6450 erret: | |
6451 vim_free(tag); | |
6452 } | |
6453 | |
6228 | 6454 /* |
6234 | 6455 * ":helpclose": Close one help window |
6228 | 6456 */ |
6457 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6458 ex_helpclose(exarg_T *eap UNUSED) |
6228 | 6459 { |
6460 win_T *win; | |
6461 | |
6462 FOR_ALL_WINDOWS(win) | |
6463 { | |
11800
5ceaecedbad2
patch 8.0.0782: using freed memory in quickfix code
Christian Brabandt <cb@256bit.org>
parents:
11666
diff
changeset
|
6464 if (bt_help(win->w_buffer)) |
6228 | 6465 { |
6466 win_close(win, FALSE); | |
6234 | 6467 return; |
6228 | 6468 } |
6469 } | |
6470 } | |
7 | 6471 |
9 | 6472 #if defined(FEAT_MULTI_LANG) || defined(PROTO) |
6473 /* | |
6474 * In an argument search for a language specifiers in the form "@xx". | |
6475 * Changes the "@" to NUL if found, and returns a pointer to "xx". | |
6476 * Returns NULL if not found. | |
6477 */ | |
6478 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6479 check_help_lang(char_u *arg) |
9 | 6480 { |
835 | 6481 int len = (int)STRLEN(arg); |
9 | 6482 |
6483 if (len >= 3 && arg[len - 3] == '@' && ASCII_ISALPHA(arg[len - 2]) | |
6484 && ASCII_ISALPHA(arg[len - 1])) | |
6485 { | |
6486 arg[len - 3] = NUL; /* remove the '@' */ | |
6487 return arg + len - 2; | |
6488 } | |
6489 return NULL; | |
6490 } | |
6491 #endif | |
6492 | |
7 | 6493 /* |
6494 * Return a heuristic indicating how well the given string matches. The | |
6495 * smaller the number, the better the match. This is the order of priorities, | |
6496 * from best match to worst match: | |
6497 * - Match with least alpha-numeric characters is better. | |
6498 * - Match with least total characters is better. | |
6499 * - Match towards the start is better. | |
6500 * - Match starting with "+" is worse (feature instead of command) | |
6501 * Assumption is made that the matched_string passed has already been found to | |
6502 * match some string for which help is requested. webb. | |
6503 */ | |
6504 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6505 help_heuristic( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6506 char_u *matched_string, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6507 int offset, /* offset for match */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6508 int wrong_case) /* no matching case */ |
7 | 6509 { |
6510 int num_letters; | |
6511 char_u *p; | |
6512 | |
6513 num_letters = 0; | |
6514 for (p = matched_string; *p; p++) | |
6515 if (ASCII_ISALNUM(*p)) | |
6516 num_letters++; | |
6517 | |
6518 /* | |
6519 * Multiply the number of letters by 100 to give it a much bigger | |
6520 * weighting than the number of characters. | |
6521 * If there only is a match while ignoring case, add 5000. | |
6522 * If the match starts in the middle of a word, add 10000 to put it | |
6523 * somewhere in the last half. | |
6524 * If the match is more than 2 chars from the start, multiply by 200 to | |
6525 * put it after matches at the start. | |
6526 */ | |
6527 if (ASCII_ISALNUM(matched_string[offset]) && offset > 0 | |
6528 && ASCII_ISALNUM(matched_string[offset - 1])) | |
6529 offset += 10000; | |
6530 else if (offset > 2) | |
6531 offset *= 200; | |
6532 if (wrong_case) | |
6533 offset += 5000; | |
6534 /* Features are less interesting than the subjects themselves, but "+" | |
6535 * alone is not a feature. */ | |
6536 if (matched_string[0] == '+' && matched_string[1] != NUL) | |
6537 offset += 100; | |
6538 return (int)(100 * num_letters + STRLEN(matched_string) + offset); | |
6539 } | |
6540 | |
6541 /* | |
6542 * Compare functions for qsort() below, that checks the help heuristics number | |
6543 * that has been put after the tagname by find_tags(). | |
6544 */ | |
6545 static int | |
6546 #ifdef __BORLANDC__ | |
6547 _RTLENTRYF | |
6548 #endif | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6549 help_compare(const void *s1, const void *s2) |
7 | 6550 { |
6551 char *p1; | |
6552 char *p2; | |
6553 | |
6554 p1 = *(char **)s1 + strlen(*(char **)s1) + 1; | |
6555 p2 = *(char **)s2 + strlen(*(char **)s2) + 1; | |
6556 return strcmp(p1, p2); | |
6557 } | |
6558 | |
6559 /* | |
6560 * Find all help tags matching "arg", sort them and return in matches[], with | |
6561 * the number of matches in num_matches. | |
6562 * The matches will be sorted with a "best" match algorithm. | |
6563 * When "keep_lang" is TRUE try keeping the language of the current buffer. | |
6564 */ | |
6565 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6566 find_help_tags( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6567 char_u *arg, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6568 int *num_matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6569 char_u ***matches, |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6570 int keep_lang) |
7 | 6571 { |
6572 char_u *s, *d; | |
6573 int i; | |
6574 static char *(mtable[]) = {"*", "g*", "[*", "]*", ":*", | |
445 | 6575 "/*", "/\\*", "\"*", "**", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6576 "cpo-*", "/\\(\\)", "/\\%(\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6577 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6578 "/\\?", "/\\z(\\)", "\\=", ":s\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6579 "[count]", "[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6580 "[range]", ":[range]", |
5647 | 6581 "[pattern]", "\\|", "\\%$", |
6582 "s/\\~", "s/\\U", "s/\\L", | |
6583 "s/\\1", "s/\\2", "s/\\3", "s/\\9"}; | |
7 | 6584 static char *(rtable[]) = {"star", "gstar", "[star", "]star", ":star", |
445 | 6585 "/star", "/\\\\star", "quotestar", "starstar", |
5269
7d1f89b27103
updated for version 7.4b.011
Bram Moolenaar <bram@vim.org>
parents:
5257
diff
changeset
|
6586 "cpo-star", "/\\\\(\\\\)", "/\\\\%(\\\\)", |
10853
b760fa91f8b3
patch 8.0.0316: :help z? does not work
Christian Brabandt <cb@256bit.org>
parents:
10851
diff
changeset
|
6587 "?", ":?", "?<CR>", "g?", "g?g?", "g??", |
279 | 6588 "/\\\\?", "/\\\\z(\\\\)", "\\\\=", ":s\\\\=", |
10851
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6589 "\\[count]", "\\[quotex]", |
256b1b96c2ad
patch 8.0.0315: :help :[range] does not work
Christian Brabandt <cb@256bit.org>
parents:
10638
diff
changeset
|
6590 "\\[range]", ":\\[range]", |
5647 | 6591 "\\[pattern]", "\\\\bar", "/\\\\%\\$", |
5867 | 6592 "s/\\\\\\~", "s/\\\\U", "s/\\\\L", |
5647 | 6593 "s/\\\\1", "s/\\\\2", "s/\\\\3", "s/\\\\9"}; |
7 | 6594 int flags; |
6595 | |
6596 d = IObuff; /* assume IObuff is long enough! */ | |
6597 | |
6598 /* | |
6599 * Recognize a few exceptions to the rule. Some strings that contain '*' | |
6600 * with "star". Otherwise '*' is recognized as a wildcard. | |
6601 */ | |
1872 | 6602 for (i = (int)(sizeof(mtable) / sizeof(char *)); --i >= 0; ) |
7 | 6603 if (STRCMP(arg, mtable[i]) == 0) |
6604 { | |
6605 STRCPY(d, rtable[i]); | |
6606 break; | |
6607 } | |
6608 | |
6609 if (i < 0) /* no match in table */ | |
6610 { | |
6611 /* Replace "\S" with "/\\S", etc. Otherwise every tag is matched. | |
6612 * Also replace "\%^" and "\%(", they match every tag too. | |
6613 * Also "\zs", "\z1", etc. | |
6614 * Also "\@<", "\@=", "\@<=", etc. | |
6615 * And also "\_$" and "\_^". */ | |
6616 if (arg[0] == '\\' | |
6617 && ((arg[1] != NUL && arg[2] == NUL) | |
6618 || (vim_strchr((char_u *)"%_z@", arg[1]) != NULL | |
6619 && arg[2] != NUL))) | |
6620 { | |
6621 STRCPY(d, "/\\\\"); | |
6622 STRCPY(d + 3, arg + 1); | |
6623 /* Check for "/\\_$", should be "/\\_\$" */ | |
6624 if (d[3] == '_' && d[4] == '$') | |
6625 STRCPY(d + 4, "\\$"); | |
6626 } | |
6627 else | |
6628 { | |
3786 | 6629 /* Replace: |
6630 * "[:...:]" with "\[:...:]" | |
6631 * "[++...]" with "\[++...]" | |
5867 | 6632 * "\{" with "\\{" -- matching "} \}" |
3786 | 6633 */ |
6634 if ((arg[0] == '[' && (arg[1] == ':' | |
6635 || (arg[1] == '+' && arg[2] == '+'))) | |
6636 || (arg[0] == '\\' && arg[1] == '{')) | |
7 | 6637 *d++ = '\\'; |
6638 | |
8556
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6639 /* |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6640 * 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
|
6641 */ |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6642 if (*arg == '(' && arg[1] == '\'') |
f4dca5239317
commit https://github.com/vim/vim/commit/00f9e0dbbd3472db217d56639fad9346b9eb3b82
Christian Brabandt <cb@256bit.org>
parents:
8544
diff
changeset
|
6643 arg++; |
7 | 6644 for (s = arg; *s; ++s) |
6645 { | |
6646 /* | |
6647 * Replace "|" with "bar" and '"' with "quote" to match the name of | |
6648 * the tags for these commands. | |
6649 * Replace "*" with ".*" and "?" with "." to match command line | |
6650 * completion. | |
6651 * Insert a backslash before '~', '$' and '.' to avoid their | |
6652 * special meaning. | |
6653 */ | |
6654 if (d - IObuff > IOSIZE - 10) /* getting too long!? */ | |
6655 break; | |
6656 switch (*s) | |
6657 { | |
6658 case '|': STRCPY(d, "bar"); | |
6659 d += 3; | |
6660 continue; | |
6661 case '"': STRCPY(d, "quote"); | |
6662 d += 5; | |
6663 continue; | |
6664 case '*': *d++ = '.'; | |
6665 break; | |
6666 case '?': *d++ = '.'; | |
6667 continue; | |
6668 case '$': | |
6669 case '.': | |
6670 case '~': *d++ = '\\'; | |
6671 break; | |
6672 } | |
6673 | |
6674 /* | |
6675 * Replace "^x" by "CTRL-X". Don't do this for "^_" to make | |
6676 * ":help i_^_CTRL-D" work. | |
6677 * Insert '-' before and after "CTRL-X" when applicable. | |
6678 */ | |
6679 if (*s < ' ' || (*s == '^' && s[1] && (ASCII_ISALPHA(s[1]) | |
6680 || vim_strchr((char_u *)"?@[\\]^", s[1]) != NULL))) | |
6681 { | |
5282
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6682 if (d > IObuff && d[-1] != '_' && d[-1] != '\\') |
8c42772f0543
updated for version 7.4b.017
Bram Moolenaar <bram@vim.org>
parents:
5269
diff
changeset
|
6683 *d++ = '_'; /* prepend a '_' to make x_CTRL-x */ |
7 | 6684 STRCPY(d, "CTRL-"); |
6685 d += 5; | |
6686 if (*s < ' ') | |
6687 { | |
6688 #ifdef EBCDIC | |
6689 *d++ = CtrlChar(*s); | |
6690 #else | |
6691 *d++ = *s + '@'; | |
6692 #endif | |
6693 if (d[-1] == '\\') | |
6694 *d++ = '\\'; /* double a backslash */ | |
6695 } | |
6696 else | |
6697 *d++ = *++s; | |
6698 if (s[1] != NUL && s[1] != '_') | |
6699 *d++ = '_'; /* append a '_' */ | |
6700 continue; | |
6701 } | |
6702 else if (*s == '^') /* "^" or "CTRL-^" or "^_" */ | |
6703 *d++ = '\\'; | |
6704 | |
6705 /* | |
6706 * Insert a backslash before a backslash after a slash, for search | |
6707 * pattern tags: "/\|" --> "/\\|". | |
6708 */ | |
6709 else if (s[0] == '\\' && s[1] != '\\' | |
6710 && *arg == '/' && s == arg + 1) | |
6711 *d++ = '\\'; | |
6712 | |
6713 /* "CTRL-\_" -> "CTRL-\\_" to avoid the special meaning of "\_" in | |
6714 * "CTRL-\_CTRL-N" */ | |
6715 if (STRNICMP(s, "CTRL-\\_", 7) == 0) | |
6716 { | |
6717 STRCPY(d, "CTRL-\\\\"); | |
6718 d += 7; | |
6719 s += 6; | |
6720 } | |
6721 | |
6722 *d++ = *s; | |
6723 | |
6724 /* | |
8883
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6725 * 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
|
6726 * 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
|
6727 */ |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6728 if (*s == '(' && (s[1] == '{' || s[1] =='[')) |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6729 break; |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6730 |
b7de875169e6
commit https://github.com/vim/vim/commit/81edd171a9465cf99cede4fa4a7b7bca3d538b0f
Christian Brabandt <cb@256bit.org>
parents:
8879
diff
changeset
|
6731 /* |
7 | 6732 * If tag starts with ', toss everything after a second '. Fixes |
6733 * CTRL-] on 'option'. (would include the trailing '.'). | |
6734 */ | |
6735 if (*s == '\'' && s > arg && *arg == '\'') | |
6736 break; | |
9234
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6737 /* Also '{' and '}'. */ |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6738 if (*s == '}' && s > arg && *arg == '{') |
6e80397a592c
commit https://github.com/vim/vim/commit/28b942a064dd486cc241894b625ab72f5a5c6d1b
Christian Brabandt <cb@256bit.org>
parents:
8883
diff
changeset
|
6739 break; |
7 | 6740 } |
6741 *d = NUL; | |
3480 | 6742 |
6743 if (*IObuff == '`') | |
6744 { | |
6745 if (d > IObuff + 2 && d[-1] == '`') | |
6746 { | |
6747 /* remove the backticks from `command` */ | |
6748 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6749 d[-2] = NUL; | |
6750 } | |
6751 else if (d > IObuff + 3 && d[-2] == '`' && d[-1] == ',') | |
6752 { | |
6753 /* remove the backticks and comma from `command`, */ | |
6754 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6755 d[-3] = NUL; | |
6756 } | |
6757 else if (d > IObuff + 4 && d[-3] == '`' | |
6758 && d[-2] == '\\' && d[-1] == '.') | |
6759 { | |
6760 /* remove the backticks and dot from `command`\. */ | |
6761 mch_memmove(IObuff, IObuff + 1, STRLEN(IObuff)); | |
6762 d[-4] = NUL; | |
6763 } | |
6764 } | |
7 | 6765 } |
6766 } | |
6767 | |
6768 *matches = (char_u **)""; | |
6769 *num_matches = 0; | |
6770 flags = TAG_HELP | TAG_REGEXP | TAG_NAMES | TAG_VERBOSE; | |
6771 if (keep_lang) | |
6772 flags |= TAG_KEEP_LANG; | |
1696 | 6773 if (find_tags(IObuff, num_matches, matches, flags, (int)MAXCOL, NULL) == OK |
7 | 6774 && *num_matches > 0) |
1696 | 6775 { |
7 | 6776 /* Sort the matches found on the heuristic number that is after the |
6777 * tag name. */ | |
6778 qsort((void *)*matches, (size_t)*num_matches, | |
6779 sizeof(char_u *), help_compare); | |
1696 | 6780 /* Delete more than TAG_MANY to reduce the size of the listing. */ |
6781 while (*num_matches > TAG_MANY) | |
6782 vim_free((*matches)[--*num_matches]); | |
6783 } | |
7 | 6784 return OK; |
6785 } | |
6786 | |
6787 /* | |
6365 | 6788 * Called when starting to edit a buffer for a help file. |
6789 */ | |
6790 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6791 prepare_help_buffer(void) |
6365 | 6792 { |
6793 char_u *p; | |
6794 | |
6795 curbuf->b_help = TRUE; | |
6796 #ifdef FEAT_QUICKFIX | |
6797 set_string_option_direct((char_u *)"buftype", -1, | |
6798 (char_u *)"help", OPT_FREE|OPT_LOCAL, 0); | |
6799 #endif | |
6800 | |
6801 /* | |
6802 * Always set these options after jumping to a help tag, because the | |
6803 * user may have an autocommand that gets in the way. | |
6804 * Accept all ASCII chars for keywords, except ' ', '*', '"', '|', and | |
6805 * latin1 word characters (for translated help files). | |
6806 * Only set it when needed, buf_init_chartab() is some work. | |
6807 */ | |
6808 p = | |
6809 #ifdef EBCDIC | |
6810 (char_u *)"65-255,^*,^|,^\""; | |
6811 #else | |
6812 (char_u *)"!-~,^*,^|,^\",192-255"; | |
6813 #endif | |
6814 if (STRCMP(curbuf->b_p_isk, p) != 0) | |
6815 { | |
6816 set_string_option_direct((char_u *)"isk", -1, p, OPT_FREE|OPT_LOCAL, 0); | |
6817 check_buf_options(curbuf); | |
6818 (void)buf_init_chartab(curbuf, FALSE); | |
6819 } | |
6820 | |
6415 | 6821 #ifdef FEAT_FOLDING |
6365 | 6822 /* Don't use the global foldmethod.*/ |
6823 set_string_option_direct((char_u *)"fdm", -1, (char_u *)"manual", | |
6824 OPT_FREE|OPT_LOCAL, 0); | |
6415 | 6825 #endif |
6365 | 6826 |
6827 curbuf->b_p_ts = 8; /* 'tabstop' is 8 */ | |
6828 curwin->w_p_list = FALSE; /* no list mode */ | |
6829 | |
6830 curbuf->b_p_ma = FALSE; /* not modifiable */ | |
6831 curbuf->b_p_bin = FALSE; /* reset 'bin' before reading file */ | |
6832 curwin->w_p_nu = 0; /* no line numbers */ | |
6833 curwin->w_p_rnu = 0; /* no relative line numbers */ | |
6834 RESET_BINDING(curwin); /* no scroll or cursor binding */ | |
6835 #ifdef FEAT_ARABIC | |
6836 curwin->w_p_arab = FALSE; /* no arabic mode */ | |
6837 #endif | |
6838 #ifdef FEAT_RIGHTLEFT | |
6839 curwin->w_p_rl = FALSE; /* help window is left-to-right */ | |
6840 #endif | |
6841 #ifdef FEAT_FOLDING | |
6842 curwin->w_p_fen = FALSE; /* No folding in the help window */ | |
6843 #endif | |
6844 #ifdef FEAT_DIFF | |
6845 curwin->w_p_diff = FALSE; /* No 'diff' */ | |
6846 #endif | |
6847 #ifdef FEAT_SPELL | |
6848 curwin->w_p_spell = FALSE; /* No spell checking */ | |
6849 #endif | |
6850 | |
6851 set_buflisted(FALSE); | |
6852 } | |
6853 | |
6854 /* | |
7 | 6855 * After reading a help file: May cleanup a help buffer when syntax |
6856 * highlighting is not used. | |
6857 */ | |
6858 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
6859 fix_help_buffer(void) |
7 | 6860 { |
6861 linenr_T lnum; | |
6862 char_u *line; | |
6863 int in_example = FALSE; | |
6864 int len; | |
3141 | 6865 char_u *fname; |
7 | 6866 char_u *p; |
6867 char_u *rt; | |
6868 int mustfree; | |
6869 | |
11533
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6870 /* Set filetype to "help" if still needed. */ |
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6871 if (STRCMP(curbuf->b_p_ft, "help") != 0) |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6872 { |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6873 ++curbuf_lock; |
11533
c83dd5fa40d8
patch 8.0.0649: when opening a help file the filetype is set several times
Christian Brabandt <cb@256bit.org>
parents:
11521
diff
changeset
|
6874 set_option_value((char_u *)"ft", 0L, (char_u *)"help", OPT_LOCAL); |
11589
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6875 --curbuf_lock; |
39787def24bb
patch 8.0.0677: setting 'filetype' may switch buffers
Christian Brabandt <cb@256bit.org>
parents:
11537
diff
changeset
|
6876 } |
7 | 6877 |
6878 #ifdef FEAT_SYN_HL | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
6879 if (!syntax_present(curwin)) |
7 | 6880 #endif |
6881 { | |
6882 for (lnum = 1; lnum <= curbuf->b_ml.ml_line_count; ++lnum) | |
6883 { | |
6884 line = ml_get_buf(curbuf, lnum, FALSE); | |
6885 len = (int)STRLEN(line); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
6886 if (in_example && len > 0 && !VIM_ISWHITE(line[0])) |
7 | 6887 { |
6888 /* End of example: non-white or '<' in first column. */ | |
6889 if (line[0] == '<') | |
6890 { | |
6891 /* blank-out a '<' in the first column */ | |
6892 line = ml_get_buf(curbuf, lnum, TRUE); | |
6893 line[0] = ' '; | |
6894 } | |
6895 in_example = FALSE; | |
6896 } | |
6897 if (!in_example && len > 0) | |
6898 { | |
6899 if (line[len - 1] == '>' && (len == 1 || line[len - 2] == ' ')) | |
6900 { | |
6901 /* blank-out a '>' in the last column (start of example) */ | |
6902 line = ml_get_buf(curbuf, lnum, TRUE); | |
6903 line[len - 1] = ' '; | |
6904 in_example = TRUE; | |
6905 } | |
6906 else if (line[len - 1] == '~') | |
6907 { | |
6908 /* blank-out a '~' at the end of line (header marker) */ | |
6909 line = ml_get_buf(curbuf, lnum, TRUE); | |
6910 line[len - 1] = ' '; | |
6911 } | |
6912 } | |
6913 } | |
6914 } | |
6915 | |
6916 /* | |
3141 | 6917 * In the "help.txt" and "help.abx" file, add the locally added help |
6918 * files. This uses the very first line in the help file. | |
7 | 6919 */ |
3141 | 6920 fname = gettail(curbuf->b_fname); |
6921 if (fnamecmp(fname, "help.txt") == 0 | |
6922 #ifdef FEAT_MULTI_LANG | |
6923 || (fnamencmp(fname, "help.", 5) == 0 | |
6924 && ASCII_ISALPHA(fname[5]) | |
6925 && ASCII_ISALPHA(fname[6]) | |
6926 && TOLOWER_ASC(fname[7]) == 'x' | |
6927 && fname[8] == NUL) | |
6928 #endif | |
6929 ) | |
7 | 6930 { |
6931 for (lnum = 1; lnum < curbuf->b_ml.ml_line_count; ++lnum) | |
6932 { | |
6933 line = ml_get_buf(curbuf, lnum, FALSE); | |
3141 | 6934 if (strstr((char *)line, "*local-additions*") == NULL) |
6935 continue; | |
6936 | |
6937 /* Go through all directories in 'runtimepath', skipping | |
6938 * $VIMRUNTIME. */ | |
6939 p = p_rtp; | |
6940 while (*p != NUL) | |
7 | 6941 { |
3141 | 6942 copy_option_part(&p, NameBuff, MAXPATHL, ","); |
6943 mustfree = FALSE; | |
6944 rt = vim_getenv((char_u *)"VIMRUNTIME", &mustfree); | |
13276
6958e700a458
patch 8.0.1512: warning for possibly using NULL pointer
Christian Brabandt <cb@256bit.org>
parents:
13268
diff
changeset
|
6945 if (rt != NULL && fullpathcmp(rt, NameBuff, FALSE) != FPC_SAME) |
7 | 6946 { |
3141 | 6947 int fcount; |
6948 char_u **fnames; | |
6949 FILE *fd; | |
6950 char_u *s; | |
6951 int fi; | |
7 | 6952 #ifdef FEAT_MBYTE |
3141 | 6953 vimconv_T vc; |
6954 char_u *cp; | |
6955 #endif | |
6956 | |
6957 /* Find all "doc/ *.txt" files in this directory. */ | |
6958 add_pathsep(NameBuff); | |
6959 #ifdef FEAT_MULTI_LANG | |
6960 STRCAT(NameBuff, "doc/*.??[tx]"); | |
7 | 6961 #else |
3141 | 6962 STRCAT(NameBuff, "doc/*.txt"); |
6963 #endif | |
6964 if (gen_expand_wildcards(1, &NameBuff, &fcount, | |
6965 &fnames, EW_FILE|EW_SILENT) == OK | |
6966 && fcount > 0) | |
6967 { | |
6968 #ifdef FEAT_MULTI_LANG | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6969 int i1, i2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6970 char_u *f1, *f2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6971 char_u *t1, *t2; |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6972 char_u *e1, *e2; |
3141 | 6973 |
6974 /* If foo.abx is found use it instead of foo.txt in | |
6975 * the same directory. */ | |
6976 for (i1 = 0; i1 < fcount; ++i1) | |
6977 { | |
6978 for (i2 = 0; i2 < fcount; ++i2) | |
6979 { | |
6980 if (i1 == i2) | |
6981 continue; | |
6982 if (fnames[i1] == NULL || fnames[i2] == NULL) | |
6983 continue; | |
6984 f1 = fnames[i1]; | |
6985 f2 = fnames[i2]; | |
6986 t1 = gettail(f1); | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6987 t2 = gettail(f2); |
3141 | 6988 e1 = vim_strrchr(t1, '.'); |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6989 e2 = vim_strrchr(t2, '.'); |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
6990 if (e1 == NULL || e2 == NULL) |
3141 | 6991 continue; |
6992 if (fnamecmp(e1, ".txt") != 0 | |
6993 && fnamecmp(e1, fname + 4) != 0) | |
6994 { | |
6995 /* Not .txt and not .abx, remove it. */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
6996 VIM_CLEAR(fnames[i1]); |
3141 | 6997 continue; |
6998 } | |
13014
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
6999 if (e1 - f1 != e2 - f2 |
e1deb00ffc27
patch 8.0.1383: local additions in help skips some files
Christian Brabandt <cb@256bit.org>
parents:
13012
diff
changeset
|
7000 || fnamencmp(f1, f2, e1 - f1) != 0) |
3141 | 7001 continue; |
7002 if (fnamecmp(e1, ".txt") == 0 | |
7003 && fnamecmp(e2, fname + 4) == 0) | |
7004 /* use .abx instead of .txt */ | |
13244
ac42c4b11dbc
patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents:
13174
diff
changeset
|
7005 VIM_CLEAR(fnames[i1]); |
7 | 7006 } |
7007 } | |
3141 | 7008 #endif |
7009 for (fi = 0; fi < fcount; ++fi) | |
7010 { | |
7011 if (fnames[fi] == NULL) | |
7012 continue; | |
7013 fd = mch_fopen((char *)fnames[fi], "r"); | |
7014 if (fd != NULL) | |
7015 { | |
7016 vim_fgets(IObuff, IOSIZE, fd); | |
7017 if (IObuff[0] == '*' | |
7018 && (s = vim_strchr(IObuff + 1, '*')) | |
7019 != NULL) | |
7020 { | |
7021 #ifdef FEAT_MBYTE | |
7022 int this_utf = MAYBE; | |
7023 #endif | |
7024 /* Change tag definition to a | |
7025 * reference and remove <CR>/<NL>. */ | |
7026 IObuff[0] = '|'; | |
7027 *s = '|'; | |
7028 while (*s != NUL) | |
7029 { | |
7030 if (*s == '\r' || *s == '\n') | |
7031 *s = NUL; | |
7032 #ifdef FEAT_MBYTE | |
7033 /* The text is utf-8 when a byte | |
7034 * above 127 is found and no | |
7035 * illegal byte sequence is found. | |
7036 */ | |
7037 if (*s >= 0x80 && this_utf != FALSE) | |
7038 { | |
7039 int l; | |
7040 | |
7041 this_utf = TRUE; | |
7042 l = utf_ptr2len(s); | |
7043 if (l == 1) | |
7044 this_utf = FALSE; | |
7045 s += l - 1; | |
7046 } | |
7047 #endif | |
7048 ++s; | |
7049 } | |
7050 #ifdef FEAT_MBYTE | |
7051 /* The help file is latin1 or utf-8; | |
7052 * conversion to the current | |
7053 * 'encoding' may be required. */ | |
7054 vc.vc_type = CONV_NONE; | |
7055 convert_setup(&vc, (char_u *)( | |
7056 this_utf == TRUE ? "utf-8" | |
7057 : "latin1"), p_enc); | |
7058 if (vc.vc_type == CONV_NONE) | |
7059 /* No conversion needed. */ | |
7060 cp = IObuff; | |
7061 else | |
7062 { | |
7063 /* Do the conversion. If it fails | |
7064 * use the unconverted text. */ | |
7065 cp = string_convert(&vc, IObuff, | |
7066 NULL); | |
7067 if (cp == NULL) | |
7068 cp = IObuff; | |
7069 } | |
7070 convert_setup(&vc, NULL, NULL); | |
7071 | |
7072 ml_append(lnum, cp, (colnr_T)0, FALSE); | |
7073 if (cp != IObuff) | |
7074 vim_free(cp); | |
7075 #else | |
7076 ml_append(lnum, IObuff, (colnr_T)0, | |
7077 FALSE); | |
7078 #endif | |
7079 ++lnum; | |
7080 } | |
7081 fclose(fd); | |
7082 } | |
7083 } | |
7084 FreeWild(fcount, fnames); | |
7 | 7085 } |
7086 } | |
3141 | 7087 if (mustfree) |
7088 vim_free(rt); | |
7 | 7089 } |
3141 | 7090 break; |
7 | 7091 } |
7092 } | |
7093 } | |
7094 | |
40 | 7095 /* |
7096 * ":exusage" | |
7097 */ | |
7098 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7099 ex_exusage(exarg_T *eap UNUSED) |
40 | 7100 { |
7101 do_cmdline_cmd((char_u *)"help ex-cmd-index"); | |
7102 } | |
7103 | |
7104 /* | |
7105 * ":viusage" | |
7106 */ | |
7107 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7108 ex_viusage(exarg_T *eap UNUSED) |
40 | 7109 { |
7110 do_cmdline_cmd((char_u *)"help normal-index"); | |
7111 } | |
7112 | |
7 | 7113 /* |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7114 * Generate tags in one help directory. |
7 | 7115 */ |
7116 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7117 helptags_one( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7118 char_u *dir, /* doc directory */ |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7119 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
|
7120 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
|
7121 int add_help_tags) /* add "help-tags" tag */ |
7 | 7122 { |
7123 FILE *fd_tags; | |
7124 FILE *fd; | |
7125 garray_T ga; | |
7126 int filecount; | |
7127 char_u **files; | |
7128 char_u *p1, *p2; | |
7129 int fi; | |
7130 char_u *s; | |
7131 int i; | |
7132 char_u *fname; | |
3957 | 7133 int dirlen; |
7 | 7134 # ifdef FEAT_MBYTE |
7135 int utf8 = MAYBE; | |
7136 int this_utf8; | |
7137 int firstline; | |
7138 int mix = FALSE; /* detected mixed encodings */ | |
7139 # endif | |
7140 | |
7141 /* | |
7142 * Find all *.txt files. | |
7143 */ | |
3978 | 7144 dirlen = (int)STRLEN(dir); |
7 | 7145 STRCPY(NameBuff, dir); |
3957 | 7146 STRCAT(NameBuff, "/**/*"); |
7 | 7147 STRCAT(NameBuff, ext); |
7148 if (gen_expand_wildcards(1, &NameBuff, &filecount, &files, | |
7149 EW_FILE|EW_SILENT) == FAIL | |
7150 || filecount == 0) | |
7151 { | |
7152 if (!got_int) | |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7153 EMSG2(_("E151: No match: %s"), NameBuff); |
7 | 7154 return; |
7155 } | |
7156 | |
7157 /* | |
7158 * Open the tags file for writing. | |
7159 * Do this before scanning through all the files. | |
7160 */ | |
7161 STRCPY(NameBuff, dir); | |
7162 add_pathsep(NameBuff); | |
7163 STRCAT(NameBuff, tagfname); | |
531 | 7164 fd_tags = mch_fopen((char *)NameBuff, "w"); |
7 | 7165 if (fd_tags == NULL) |
7166 { | |
7167 EMSG2(_("E152: Cannot open %s for writing"), NameBuff); | |
7168 FreeWild(filecount, files); | |
7169 return; | |
7170 } | |
7171 | |
7172 /* | |
1502 | 7173 * If using the "++t" argument or generating tags for "$VIMRUNTIME/doc" |
7174 * add the "help-tags" tag. | |
7 | 7175 */ |
7176 ga_init2(&ga, (int)sizeof(char_u *), 100); | |
1502 | 7177 if (add_help_tags || fullpathcmp((char_u *)"$VIMRUNTIME/doc", |
7178 dir, FALSE) == FPC_SAME) | |
7 | 7179 { |
7180 if (ga_grow(&ga, 1) == FAIL) | |
7181 got_int = TRUE; | |
7182 else | |
7183 { | |
835 | 7184 s = alloc(18 + (unsigned)STRLEN(tagfname)); |
7 | 7185 if (s == NULL) |
7186 got_int = TRUE; | |
7187 else | |
7188 { | |
7189 sprintf((char *)s, "help-tags\t%s\t1\n", tagfname); | |
7190 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7191 ++ga.ga_len; | |
7192 } | |
7193 } | |
7194 } | |
7195 | |
7196 /* | |
7197 * Go over all the files and extract the tags. | |
7198 */ | |
7199 for (fi = 0; fi < filecount && !got_int; ++fi) | |
7200 { | |
531 | 7201 fd = mch_fopen((char *)files[fi], "r"); |
7 | 7202 if (fd == NULL) |
7203 { | |
7204 EMSG2(_("E153: Unable to open %s for reading"), files[fi]); | |
7205 continue; | |
7206 } | |
3957 | 7207 fname = files[fi] + dirlen + 1; |
7 | 7208 |
7209 # ifdef FEAT_MBYTE | |
7210 firstline = TRUE; | |
7211 # endif | |
7212 while (!vim_fgets(IObuff, IOSIZE, fd) && !got_int) | |
7213 { | |
7214 # ifdef FEAT_MBYTE | |
7215 if (firstline) | |
7216 { | |
7217 /* Detect utf-8 file by a non-ASCII char in the first line. */ | |
7218 this_utf8 = MAYBE; | |
7219 for (s = IObuff; *s != NUL; ++s) | |
7220 if (*s >= 0x80) | |
7221 { | |
7222 int l; | |
7223 | |
7224 this_utf8 = TRUE; | |
474 | 7225 l = utf_ptr2len(s); |
7 | 7226 if (l == 1) |
7227 { | |
7228 /* Illegal UTF-8 byte sequence. */ | |
7229 this_utf8 = FALSE; | |
7230 break; | |
7231 } | |
7232 s += l - 1; | |
7233 } | |
7234 if (this_utf8 == MAYBE) /* only ASCII characters found */ | |
7235 this_utf8 = FALSE; | |
7236 if (utf8 == MAYBE) /* first file */ | |
7237 utf8 = this_utf8; | |
7238 else if (utf8 != this_utf8) | |
7239 { | |
7240 EMSG2(_("E670: Mix of help file encodings within a language: %s"), files[fi]); | |
7241 mix = !got_int; | |
7242 got_int = TRUE; | |
7243 } | |
7244 firstline = FALSE; | |
7245 } | |
7246 # endif | |
7247 p1 = vim_strchr(IObuff, '*'); /* find first '*' */ | |
7248 while (p1 != NULL) | |
7249 { | |
3514 | 7250 /* Use vim_strbyte() instead of vim_strchr() so that when |
7251 * 'encoding' is dbcs it still works, don't find '*' in the | |
7252 * second byte. */ | |
7253 p2 = vim_strbyte(p1 + 1, '*'); /* find second '*' */ | |
7 | 7254 if (p2 != NULL && p2 > p1 + 1) /* skip "*" and "**" */ |
7255 { | |
7256 for (s = p1 + 1; s < p2; ++s) | |
7257 if (*s == ' ' || *s == '\t' || *s == '|') | |
7258 break; | |
7259 | |
7260 /* | |
7261 * Only accept a *tag* when it consists of valid | |
7262 * characters, there is white space before it and is | |
7263 * followed by a white character or end-of-line. | |
7264 */ | |
7265 if (s == p2 | |
7266 && (p1 == IObuff || p1[-1] == ' ' || p1[-1] == '\t') | |
7267 && (vim_strchr((char_u *)" \t\n\r", s[1]) != NULL | |
7268 || s[1] == '\0')) | |
7269 { | |
7270 *p2 = '\0'; | |
7271 ++p1; | |
7272 if (ga_grow(&ga, 1) == FAIL) | |
7273 { | |
7274 got_int = TRUE; | |
7275 break; | |
7276 } | |
7277 s = alloc((unsigned)(p2 - p1 + STRLEN(fname) + 2)); | |
7278 if (s == NULL) | |
7279 { | |
7280 got_int = TRUE; | |
7281 break; | |
7282 } | |
7283 ((char_u **)ga.ga_data)[ga.ga_len] = s; | |
7284 ++ga.ga_len; | |
7285 sprintf((char *)s, "%s\t%s", p1, fname); | |
7286 | |
7287 /* find next '*' */ | |
7288 p2 = vim_strchr(p2 + 1, '*'); | |
7289 } | |
7290 } | |
7291 p1 = p2; | |
7292 } | |
7293 line_breakcheck(); | |
7294 } | |
7295 | |
7296 fclose(fd); | |
7297 } | |
7298 | |
7299 FreeWild(filecount, files); | |
7300 | |
7301 if (!got_int) | |
7302 { | |
7303 /* | |
7304 * Sort the tags. | |
7305 */ | |
7009 | 7306 if (ga.ga_data != NULL) |
7307 sort_strings((char_u **)ga.ga_data, ga.ga_len); | |
7 | 7308 |
7309 /* | |
7310 * Check for duplicates. | |
7311 */ | |
7312 for (i = 1; i < ga.ga_len; ++i) | |
7313 { | |
7314 p1 = ((char_u **)ga.ga_data)[i - 1]; | |
7315 p2 = ((char_u **)ga.ga_data)[i]; | |
7316 while (*p1 == *p2) | |
7317 { | |
7318 if (*p2 == '\t') | |
7319 { | |
7320 *p2 = NUL; | |
274 | 7321 vim_snprintf((char *)NameBuff, MAXPATHL, |
7 | 7322 _("E154: Duplicate tag \"%s\" in file %s/%s"), |
7323 ((char_u **)ga.ga_data)[i], dir, p2 + 1); | |
7324 EMSG(NameBuff); | |
7325 *p2 = '\t'; | |
7326 break; | |
7327 } | |
7328 ++p1; | |
7329 ++p2; | |
7330 } | |
7331 } | |
7332 | |
7333 # ifdef FEAT_MBYTE | |
7334 if (utf8 == TRUE) | |
7335 fprintf(fd_tags, "!_TAG_FILE_ENCODING\tutf-8\t//\n"); | |
7336 # endif | |
7337 | |
7338 /* | |
7339 * Write the tags into the file. | |
7340 */ | |
7341 for (i = 0; i < ga.ga_len; ++i) | |
7342 { | |
7343 s = ((char_u **)ga.ga_data)[i]; | |
1325 | 7344 if (STRNCMP(s, "help-tags\t", 10) == 0) |
7 | 7345 /* help-tags entry was added in formatted form */ |
1325 | 7346 fputs((char *)s, fd_tags); |
7 | 7347 else |
7348 { | |
7349 fprintf(fd_tags, "%s\t/*", s); | |
7350 for (p1 = s; *p1 != '\t'; ++p1) | |
7351 { | |
7352 /* insert backslash before '\\' and '/' */ | |
7353 if (*p1 == '\\' || *p1 == '/') | |
7354 putc('\\', fd_tags); | |
7355 putc(*p1, fd_tags); | |
7356 } | |
7357 fprintf(fd_tags, "*\n"); | |
7358 } | |
7359 } | |
7360 } | |
7361 #ifdef FEAT_MBYTE | |
7362 if (mix) | |
7363 got_int = FALSE; /* continue with other languages */ | |
7364 #endif | |
7365 | |
7366 for (i = 0; i < ga.ga_len; ++i) | |
7367 vim_free(((char_u **)ga.ga_data)[i]); | |
7368 ga_clear(&ga); | |
7369 fclose(fd_tags); /* there is no check for an error... */ | |
7370 } | |
7371 | |
8522
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 * 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
|
7374 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7375 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7376 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
|
7377 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7378 #ifdef FEAT_MULTI_LANG |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7379 int len; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7380 int i, j; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7381 garray_T ga; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7382 char_u lang[2]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7383 char_u ext[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7384 char_u fname[8]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7385 int filecount; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7386 char_u **files; |
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 /* 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
|
7389 STRCPY(NameBuff, dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7390 add_pathsep(NameBuff); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7391 STRCAT(NameBuff, "**"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7392 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
|
7393 EW_FILE|EW_SILENT) == FAIL |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7394 || filecount == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7395 { |
9953
9560a2eb7968
commit https://github.com/vim/vim/commit/5b30291785e6b9be1a607504c14bd03c601b59a6
Christian Brabandt <cb@256bit.org>
parents:
9947
diff
changeset
|
7396 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
|
7397 return; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7398 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7399 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7400 /* 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
|
7401 * present. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7402 ga_init2(&ga, 1, 10); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7403 for (i = 0; i < filecount; ++i) |
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 len = (int)STRLEN(files[i]); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7406 if (len > 4) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7407 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7408 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
|
7409 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7410 /* ".txt" -> language "en" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7411 lang[0] = 'e'; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7412 lang[1] = 'n'; |
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 else if (files[i][len - 4] == '.' |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7415 && ASCII_ISALPHA(files[i][len - 3]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7416 && ASCII_ISALPHA(files[i][len - 2]) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7417 && 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
|
7418 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7419 /* ".abx" -> language "ab" */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7420 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
|
7421 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
|
7422 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7423 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7424 continue; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7425 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7426 /* Did we find this language already? */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7427 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
|
7428 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
|
7429 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7430 if (j == ga.ga_len) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7431 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7432 /* New language, add it. */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7433 if (ga_grow(&ga, 2) == FAIL) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7434 break; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7435 ((char_u *)ga.ga_data)[ga.ga_len++] = lang[0]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7436 ((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
|
7437 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7438 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7439 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7440 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7441 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7442 * 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
|
7443 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7444 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
|
7445 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7446 STRCPY(fname, "tags-xx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7447 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
|
7448 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
|
7449 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
|
7450 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7451 /* 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
|
7452 fname[4] = NUL; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7453 STRCPY(ext, ".txt"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7454 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7455 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7456 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7457 /* 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
|
7458 STRCPY(ext, ".xxx"); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7459 ext[1] = fname[5]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7460 ext[2] = fname[6]; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7461 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7462 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
|
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 ga_clear(&ga); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7466 FreeWild(filecount, files); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7467 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7468 #else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7469 /* 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
|
7470 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
|
7471 #endif |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7472 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7473 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7474 static void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7475 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
|
7476 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7477 do_helptags(fname, *(int *)cookie); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7478 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7479 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7480 /* |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7481 * ":helptags" |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7482 */ |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7483 void |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7484 ex_helptags(exarg_T *eap) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7485 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7486 expand_T xpc; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7487 char_u *dirname; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7488 int add_help_tags = FALSE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7489 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7490 /* Check for ":helptags ++t {dir}". */ |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7491 if (STRNCMP(eap->arg, "++t", 3) == 0 && VIM_ISWHITE(eap->arg[3])) |
8522
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7492 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7493 add_help_tags = TRUE; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7494 eap->arg = skipwhite(eap->arg + 3); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7495 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7496 |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7497 if (STRCMP(eap->arg, "ALL") == 0) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7498 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7499 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
|
7500 helptags_cb, &add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7501 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7502 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7503 { |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7504 ExpandInit(&xpc); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7505 xpc.xp_context = EXPAND_DIRECTORIES; |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7506 dirname = ExpandOne(&xpc, eap->arg, NULL, |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7507 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
|
7508 if (dirname == NULL || !mch_isdir(dirname)) |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7509 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
|
7510 else |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7511 do_helptags(dirname, add_help_tags); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7512 vim_free(dirname); |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7513 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7514 } |
721e8d6cb7b5
commit https://github.com/vim/vim/commit/6bef5306e4f2cacb3a93667992c2312d4b293c9d
Christian Brabandt <cb@256bit.org>
parents:
8212
diff
changeset
|
7515 |
7 | 7516 #if defined(FEAT_SIGNS) || defined(PROTO) |
7517 | |
7518 /* | |
7519 * Struct to hold the sign properties. | |
7520 */ | |
7521 typedef struct sign sign_T; | |
7522 | |
7523 struct sign | |
7524 { | |
7525 sign_T *sn_next; /* next sign in list */ | |
2606 | 7526 int sn_typenr; /* type number of sign */ |
7 | 7527 char_u *sn_name; /* name of sign */ |
7528 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
|
7529 # ifdef FEAT_SIGN_ICONS |
7 | 7530 void *sn_image; /* icon image */ |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7531 # endif |
7 | 7532 char_u *sn_text; /* text used instead of pixmap */ |
7533 int sn_line_hl; /* highlight ID for line */ | |
7534 int sn_text_hl; /* highlight ID for text */ | |
7535 }; | |
7536 | |
7537 static sign_T *first_sign = NULL; | |
2605 | 7538 static int next_sign_typenr = 1; |
7 | 7539 |
7799
af3c41a3c53f
commit https://github.com/vim/vim/commit/f28dbcea371b3a35727d91afc90fb90e0527d78a
Christian Brabandt <cb@256bit.org>
parents:
7691
diff
changeset
|
7540 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
|
7541 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
|
7542 static void sign_undefine(sign_T *sp, sign_T *sp_prev); |
7 | 7543 |
1868 | 7544 static char *cmds[] = { |
7545 "define", | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7546 # define SIGNCMD_DEFINE 0 |
1868 | 7547 "undefine", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7548 # define SIGNCMD_UNDEFINE 1 |
1868 | 7549 "list", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7550 # define SIGNCMD_LIST 2 |
1868 | 7551 "place", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7552 # define SIGNCMD_PLACE 3 |
1868 | 7553 "unplace", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7554 # define SIGNCMD_UNPLACE 4 |
1868 | 7555 "jump", |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7556 # define SIGNCMD_JUMP 5 |
1868 | 7557 NULL |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7558 # define SIGNCMD_LAST 6 |
1868 | 7559 }; |
7560 | |
7561 /* | |
7562 * Find index of a ":sign" subcmd from its name. | |
7563 * "*end_cmd" must be writable. | |
7564 */ | |
7565 static int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7566 sign_cmd_idx( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7567 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
|
7568 char_u *end_cmd) /* just after sign subcmd */ |
1868 | 7569 { |
7570 int idx; | |
7571 char save = *end_cmd; | |
7572 | |
7573 *end_cmd = NUL; | |
7574 for (idx = 0; ; ++idx) | |
7575 if (cmds[idx] == NULL || STRCMP(begin_cmd, cmds[idx]) == 0) | |
7576 break; | |
7577 *end_cmd = save; | |
7578 return idx; | |
7579 } | |
7580 | |
7 | 7581 /* |
7582 * ":sign" command | |
7583 */ | |
7584 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7585 ex_sign(exarg_T *eap) |
7 | 7586 { |
7587 char_u *arg = eap->arg; | |
7588 char_u *p; | |
7589 int idx; | |
7590 sign_T *sp; | |
7591 sign_T *sp_prev; | |
12820
63d87ba12c34
patch 8.0.1287: temp file used for viminfo may have wrong permissions
Christian Brabandt <cb@256bit.org>
parents:
12676
diff
changeset
|
7592 buf_T *buf = NULL; |
7 | 7593 |
7594 /* Parse the subcommand. */ | |
7595 p = skiptowhite(arg); | |
1868 | 7596 idx = sign_cmd_idx(arg, p); |
7597 if (idx == SIGNCMD_LAST) | |
7598 { | |
7599 EMSG2(_("E160: Unknown sign command: %s"), arg); | |
7600 return; | |
7 | 7601 } |
7602 arg = skipwhite(p); | |
7603 | |
7604 if (idx <= SIGNCMD_LIST) | |
7605 { | |
7606 /* | |
7607 * Define, undefine or list signs. | |
7608 */ | |
7609 if (idx == SIGNCMD_LIST && *arg == NUL) | |
7610 { | |
7611 /* ":sign list": list all defined signs */ | |
3411 | 7612 for (sp = first_sign; sp != NULL && !got_int; sp = sp->sn_next) |
7 | 7613 sign_list_defined(sp); |
7614 } | |
7615 else if (*arg == NUL) | |
7616 EMSG(_("E156: Missing sign name")); | |
7617 else | |
7618 { | |
2605 | 7619 /* Isolate the sign name. If it's a number skip leading zeroes, |
7620 * so that "099" and "99" are the same sign. But keep "0". */ | |
7 | 7621 p = skiptowhite(arg); |
7622 if (*p != NUL) | |
7623 *p++ = NUL; | |
2605 | 7624 while (arg[0] == '0' && arg[1] != NUL) |
7625 ++arg; | |
7626 | |
7 | 7627 sp_prev = NULL; |
7628 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7629 { | |
7630 if (STRCMP(sp->sn_name, arg) == 0) | |
7631 break; | |
7632 sp_prev = sp; | |
7633 } | |
7634 if (idx == SIGNCMD_DEFINE) | |
7635 { | |
7636 /* ":sign define {name} ...": define a sign */ | |
7637 if (sp == NULL) | |
7638 { | |
2605 | 7639 sign_T *lp; |
7640 int start = next_sign_typenr; | |
7641 | |
7 | 7642 /* Allocate a new sign. */ |
7643 sp = (sign_T *)alloc_clear((unsigned)sizeof(sign_T)); | |
7644 if (sp == NULL) | |
7645 return; | |
7646 | |
2605 | 7647 /* Check that next_sign_typenr is not already being used. |
7648 * This only happens after wrapping around. Hopefully | |
7649 * another one got deleted and we can use its number. */ | |
7650 for (lp = first_sign; lp != NULL; ) | |
7 | 7651 { |
2605 | 7652 if (lp->sn_typenr == next_sign_typenr) |
7 | 7653 { |
2605 | 7654 ++next_sign_typenr; |
7655 if (next_sign_typenr == MAX_TYPENR) | |
7656 next_sign_typenr = 1; | |
7657 if (next_sign_typenr == start) | |
7 | 7658 { |
2605 | 7659 vim_free(sp); |
7660 EMSG(_("E612: Too many signs defined")); | |
7661 return; | |
7 | 7662 } |
2605 | 7663 lp = first_sign; /* start all over */ |
7664 continue; | |
7 | 7665 } |
2605 | 7666 lp = lp->sn_next; |
7667 } | |
7668 | |
7669 sp->sn_typenr = next_sign_typenr; | |
7670 if (++next_sign_typenr == MAX_TYPENR) | |
7671 next_sign_typenr = 1; /* wrap around */ | |
7672 | |
7673 sp->sn_name = vim_strsave(arg); | |
7674 if (sp->sn_name == NULL) /* out of memory */ | |
7675 { | |
7676 vim_free(sp); | |
7677 return; | |
7 | 7678 } |
2601 | 7679 |
7680 /* add the new sign to the list of signs */ | |
7681 if (sp_prev == NULL) | |
7682 first_sign = sp; | |
7683 else | |
7684 sp_prev->sn_next = sp; | |
7 | 7685 } |
7686 | |
7687 /* set values for a defined sign. */ | |
7688 for (;;) | |
7689 { | |
7690 arg = skipwhite(p); | |
7691 if (*arg == NUL) | |
7692 break; | |
7693 p = skiptowhite_esc(arg); | |
7694 if (STRNCMP(arg, "icon=", 5) == 0) | |
7695 { | |
7696 arg += 5; | |
7697 vim_free(sp->sn_icon); | |
7698 sp->sn_icon = vim_strnsave(arg, (int)(p - arg)); | |
7699 backslash_halve(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7700 # ifdef FEAT_SIGN_ICONS |
7 | 7701 if (gui.in_use) |
7702 { | |
7703 out_flush(); | |
7704 if (sp->sn_image != NULL) | |
7705 gui_mch_destroy_sign(sp->sn_image); | |
7706 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
7707 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7708 # endif |
7 | 7709 } |
7710 else if (STRNCMP(arg, "text=", 5) == 0) | |
7711 { | |
7712 char_u *s; | |
7713 int cells; | |
7714 int len; | |
7715 | |
7716 arg += 5; | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7717 # ifdef FEAT_MBYTE |
7 | 7718 /* Count cells and check for non-printable chars */ |
7719 if (has_mbyte) | |
7720 { | |
7721 cells = 0; | |
474 | 7722 for (s = arg; s < p; s += (*mb_ptr2len)(s)) |
7 | 7723 { |
7724 if (!vim_isprintc((*mb_ptr2char)(s))) | |
7725 break; | |
7726 cells += (*mb_ptr2cells)(s); | |
7727 } | |
7728 } | |
7729 else | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7730 # endif |
7 | 7731 { |
7732 for (s = arg; s < p; ++s) | |
7733 if (!vim_isprintc(*s)) | |
7734 break; | |
835 | 7735 cells = (int)(s - arg); |
7 | 7736 } |
7737 /* Currently must be one or two display cells */ | |
7738 if (s != p || cells < 1 || cells > 2) | |
7739 { | |
7740 *p = NUL; | |
7741 EMSG2(_("E239: Invalid sign text: %s"), arg); | |
7742 return; | |
7743 } | |
7744 | |
7745 vim_free(sp->sn_text); | |
7746 /* Allocate one byte more if we need to pad up | |
7747 * with a space. */ | |
835 | 7748 len = (int)(p - arg + ((cells == 1) ? 1 : 0)); |
7 | 7749 sp->sn_text = vim_strnsave(arg, len); |
7750 | |
7751 if (sp->sn_text != NULL && cells == 1) | |
7752 STRCPY(sp->sn_text + len - 1, " "); | |
7753 } | |
7754 else if (STRNCMP(arg, "linehl=", 7) == 0) | |
7755 { | |
7756 arg += 7; | |
7757 sp->sn_line_hl = syn_check_group(arg, (int)(p - arg)); | |
7758 } | |
7759 else if (STRNCMP(arg, "texthl=", 7) == 0) | |
7760 { | |
7761 arg += 7; | |
7762 sp->sn_text_hl = syn_check_group(arg, (int)(p - arg)); | |
7763 } | |
7764 else | |
7765 { | |
7766 EMSG2(_(e_invarg2), arg); | |
7767 return; | |
7768 } | |
7769 } | |
7770 } | |
7771 else if (sp == NULL) | |
7772 EMSG2(_("E155: Unknown sign: %s"), arg); | |
7773 else if (idx == SIGNCMD_LIST) | |
7774 /* ":sign list {name}" */ | |
7775 sign_list_defined(sp); | |
7776 else | |
7777 /* ":sign undefine {name}" */ | |
1828 | 7778 sign_undefine(sp, sp_prev); |
7 | 7779 } |
7780 } | |
7781 else | |
7782 { | |
7783 int id = -1; | |
7784 linenr_T lnum = -1; | |
7785 char_u *sign_name = NULL; | |
7786 char_u *arg1; | |
7787 | |
7788 if (*arg == NUL) | |
7789 { | |
7790 if (idx == SIGNCMD_PLACE) | |
7791 { | |
7792 /* ":sign place": list placed signs in all buffers */ | |
7793 sign_list_placed(NULL); | |
7794 } | |
7795 else if (idx == SIGNCMD_UNPLACE) | |
7796 { | |
7797 /* ":sign unplace": remove placed sign at cursor */ | |
7798 id = buf_findsign_id(curwin->w_buffer, curwin->w_cursor.lnum); | |
7799 if (id > 0) | |
7800 { | |
7801 buf_delsign(curwin->w_buffer, id); | |
7802 update_debug_sign(curwin->w_buffer, curwin->w_cursor.lnum); | |
7803 } | |
7804 else | |
7805 EMSG(_("E159: Missing sign number")); | |
7806 } | |
7807 else | |
7808 EMSG(_(e_argreq)); | |
7809 return; | |
7810 } | |
7811 | |
7812 if (idx == SIGNCMD_UNPLACE && arg[0] == '*' && arg[1] == NUL) | |
7813 { | |
7814 /* ":sign unplace *": remove all placed signs */ | |
7815 buf_delete_all_signs(); | |
7816 return; | |
7817 } | |
7818 | |
7819 /* first arg could be placed sign id */ | |
7820 arg1 = arg; | |
7821 if (VIM_ISDIGIT(*arg)) | |
7822 { | |
7823 id = getdigits(&arg); | |
11129
f4ea50924c6d
patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
11127
diff
changeset
|
7824 if (!VIM_ISWHITE(*arg) && *arg != NUL) |
7 | 7825 { |
7826 id = -1; | |
7827 arg = arg1; | |
7828 } | |
7829 else | |
7830 { | |
7831 arg = skipwhite(arg); | |
7832 if (idx == SIGNCMD_UNPLACE && *arg == NUL) | |
7833 { | |
7834 /* ":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
|
7835 FOR_ALL_BUFFERS(buf) |
7 | 7836 if ((lnum = buf_delsign(buf, id)) != 0) |
7837 update_debug_sign(buf, lnum); | |
7838 return; | |
7839 } | |
7840 } | |
7841 } | |
7842 | |
7843 /* | |
7844 * Check for line={lnum} name={name} and file={fname} or buffer={nr}. | |
7845 * Leave "arg" pointing to {fname}. | |
7846 */ | |
7847 for (;;) | |
7848 { | |
7849 if (STRNCMP(arg, "line=", 5) == 0) | |
7850 { | |
7851 arg += 5; | |
7852 lnum = atoi((char *)arg); | |
7853 arg = skiptowhite(arg); | |
7854 } | |
3672 | 7855 else if (STRNCMP(arg, "*", 1) == 0 && idx == SIGNCMD_UNPLACE) |
7856 { | |
7857 if (id != -1) | |
7858 { | |
7859 EMSG(_(e_invarg)); | |
7860 return; | |
7861 } | |
7862 id = -2; | |
7863 arg = skiptowhite(arg + 1); | |
7864 } | |
7 | 7865 else if (STRNCMP(arg, "name=", 5) == 0) |
7866 { | |
7867 arg += 5; | |
7868 sign_name = arg; | |
7869 arg = skiptowhite(arg); | |
7870 if (*arg != NUL) | |
7871 *arg++ = NUL; | |
2605 | 7872 while (sign_name[0] == '0' && sign_name[1] != NUL) |
7873 ++sign_name; | |
7 | 7874 } |
7875 else if (STRNCMP(arg, "file=", 5) == 0) | |
7876 { | |
7877 arg += 5; | |
7878 buf = buflist_findname(arg); | |
7879 break; | |
7880 } | |
7881 else if (STRNCMP(arg, "buffer=", 7) == 0) | |
7882 { | |
7883 arg += 7; | |
7884 buf = buflist_findnr((int)getdigits(&arg)); | |
7885 if (*skipwhite(arg) != NUL) | |
7886 EMSG(_(e_trailing)); | |
7887 break; | |
7888 } | |
7889 else | |
7890 { | |
7891 EMSG(_(e_invarg)); | |
7892 return; | |
7893 } | |
7894 arg = skipwhite(arg); | |
7895 } | |
7896 | |
7897 if (buf == NULL) | |
7898 { | |
7899 EMSG2(_("E158: Invalid buffer name: %s"), arg); | |
7900 } | |
3672 | 7901 else if (id <= 0 && !(idx == SIGNCMD_UNPLACE && id == -2)) |
7 | 7902 { |
7903 if (lnum >= 0 || sign_name != NULL) | |
7904 EMSG(_(e_invarg)); | |
7905 else | |
7906 /* ":sign place file={fname}": list placed signs in one file */ | |
7907 sign_list_placed(buf); | |
7908 } | |
7909 else if (idx == SIGNCMD_JUMP) | |
7910 { | |
7911 /* ":sign jump {id} file={fname}" */ | |
7912 if (lnum >= 0 || sign_name != NULL) | |
7913 EMSG(_(e_invarg)); | |
7914 else if ((lnum = buf_findsign(buf, id)) > 0) | |
7915 { /* goto a sign ... */ | |
7916 if (buf_jump_open_win(buf) != NULL) | |
7917 { /* ... in a current window */ | |
7918 curwin->w_cursor.lnum = lnum; | |
7919 check_cursor_lnum(); | |
7920 beginline(BL_WHITE); | |
7921 } | |
7922 else | |
7923 { /* ... not currently in a window */ | |
7924 char_u *cmd; | |
7925 | |
9902
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7926 if (buf->b_fname == NULL) |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7927 { |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7928 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
|
7929 return; |
5a667a3a3743
commit https://github.com/vim/vim/commit/bfd096d02087a10e8e2f4bdfb74e0435506fa8bb
Christian Brabandt <cb@256bit.org>
parents:
9890
diff
changeset
|
7930 } |
7 | 7931 cmd = alloc((unsigned)STRLEN(buf->b_fname) + 25); |
7932 if (cmd == NULL) | |
7933 return; | |
7934 sprintf((char *)cmd, "e +%ld %s", (long)lnum, buf->b_fname); | |
7935 do_cmdline_cmd(cmd); | |
7936 vim_free(cmd); | |
7937 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7938 # ifdef FEAT_FOLDING |
7 | 7939 foldOpenCursor(); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7940 # endif |
7 | 7941 } |
7942 else | |
7943 EMSGN(_("E157: Invalid sign ID: %ld"), id); | |
7944 } | |
7945 else if (idx == SIGNCMD_UNPLACE) | |
7946 { | |
7947 if (lnum >= 0 || sign_name != NULL) | |
7948 EMSG(_(e_invarg)); | |
3672 | 7949 else if (id == -2) |
7950 { | |
7951 /* ":sign unplace * file={fname}" */ | |
7952 redraw_buf_later(buf, NOT_VALID); | |
7953 buf_delete_signs(buf); | |
7954 } | |
7 | 7955 else |
7956 { | |
3672 | 7957 /* ":sign unplace {id} file={fname}" */ |
7 | 7958 lnum = buf_delsign(buf, id); |
7959 update_debug_sign(buf, lnum); | |
7960 } | |
7961 } | |
7962 /* idx == SIGNCMD_PLACE */ | |
7963 else if (sign_name != NULL) | |
7964 { | |
7965 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
7966 if (STRCMP(sp->sn_name, sign_name) == 0) | |
7967 break; | |
7968 if (sp == NULL) | |
7969 { | |
7970 EMSG2(_("E155: Unknown sign: %s"), sign_name); | |
7971 return; | |
7972 } | |
7973 if (lnum > 0) | |
7974 /* ":sign place {id} line={lnum} name={name} file={fname}": | |
7975 * place a sign */ | |
7976 buf_addsign(buf, id, lnum, sp->sn_typenr); | |
7977 else | |
7978 /* ":sign place {id} file={fname}": change sign type */ | |
7979 lnum = buf_change_sign_type(buf, id, sp->sn_typenr); | |
5865 | 7980 if (lnum > 0) |
7981 update_debug_sign(buf, lnum); | |
7982 else | |
7983 EMSG2(_("E885: Not possible to change sign %s"), sign_name); | |
7 | 7984 } |
7985 else | |
7986 EMSG(_(e_invarg)); | |
7987 } | |
7988 } | |
7989 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
7990 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 7991 /* |
7992 * Allocate the icons. Called when the GUI has started. Allows defining | |
7993 * signs before it starts. | |
7994 */ | |
7995 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
7996 sign_gui_started(void) |
7 | 7997 { |
7998 sign_T *sp; | |
7999 | |
8000 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8001 if (sp->sn_icon != NULL) | |
8002 sp->sn_image = gui_mch_register_sign(sp->sn_icon); | |
8003 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8004 # endif |
7 | 8005 |
8006 /* | |
8007 * List one sign. | |
8008 */ | |
8009 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8010 sign_list_defined(sign_T *sp) |
7 | 8011 { |
8012 char_u *p; | |
8013 | |
274 | 8014 smsg((char_u *)"sign %s", sp->sn_name); |
7 | 8015 if (sp->sn_icon != NULL) |
8016 { | |
8017 MSG_PUTS(" icon="); | |
8018 msg_outtrans(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8019 # ifdef FEAT_SIGN_ICONS |
7 | 8020 if (sp->sn_image == NULL) |
8021 MSG_PUTS(_(" (NOT FOUND)")); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8022 # else |
7 | 8023 MSG_PUTS(_(" (not supported)")); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8024 # endif |
7 | 8025 } |
8026 if (sp->sn_text != NULL) | |
8027 { | |
8028 MSG_PUTS(" text="); | |
8029 msg_outtrans(sp->sn_text); | |
8030 } | |
8031 if (sp->sn_line_hl > 0) | |
8032 { | |
8033 MSG_PUTS(" linehl="); | |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8034 p = get_highlight_name_ext(NULL, sp->sn_line_hl - 1, FALSE); |
7 | 8035 if (p == NULL) |
8036 MSG_PUTS("NONE"); | |
8037 else | |
8038 msg_puts(p); | |
8039 } | |
8040 if (sp->sn_text_hl > 0) | |
8041 { | |
8042 MSG_PUTS(" texthl="); | |
11254
918942a3b0ef
patch 8.0.0513: getting name of cleared highlight group is wrong
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
8043 p = get_highlight_name_ext(NULL, sp->sn_text_hl - 1, FALSE); |
7 | 8044 if (p == NULL) |
8045 MSG_PUTS("NONE"); | |
8046 else | |
8047 msg_puts(p); | |
8048 } | |
8049 } | |
8050 | |
8051 /* | |
1828 | 8052 * Undefine a sign and free its memory. |
8053 */ | |
8054 static void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8055 sign_undefine(sign_T *sp, sign_T *sp_prev) |
1828 | 8056 { |
8057 vim_free(sp->sn_name); | |
8058 vim_free(sp->sn_icon); | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8059 # ifdef FEAT_SIGN_ICONS |
1828 | 8060 if (sp->sn_image != NULL) |
8061 { | |
8062 out_flush(); | |
8063 gui_mch_destroy_sign(sp->sn_image); | |
8064 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8065 # endif |
1828 | 8066 vim_free(sp->sn_text); |
8067 if (sp_prev == NULL) | |
8068 first_sign = sp->sn_next; | |
8069 else | |
8070 sp_prev->sn_next = sp->sn_next; | |
8071 vim_free(sp); | |
8072 } | |
8073 | |
8074 /* | |
7 | 8075 * Get highlighting attribute for sign "typenr". |
8076 * If "line" is TRUE: line highl, if FALSE: text highl. | |
8077 */ | |
8078 int | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8079 sign_get_attr(int typenr, int line) |
7 | 8080 { |
8081 sign_T *sp; | |
8082 | |
8083 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8084 if (sp->sn_typenr == typenr) | |
8085 { | |
8086 if (line) | |
8087 { | |
8088 if (sp->sn_line_hl > 0) | |
8089 return syn_id2attr(sp->sn_line_hl); | |
8090 } | |
8091 else | |
8092 { | |
8093 if (sp->sn_text_hl > 0) | |
8094 return syn_id2attr(sp->sn_text_hl); | |
8095 } | |
8096 break; | |
8097 } | |
8098 return 0; | |
8099 } | |
8100 | |
8101 /* | |
8102 * Get text mark for sign "typenr". | |
8103 * Returns NULL if there isn't one. | |
8104 */ | |
8105 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8106 sign_get_text(int typenr) |
7 | 8107 { |
8108 sign_T *sp; | |
8109 | |
8110 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8111 if (sp->sn_typenr == typenr) | |
8112 return sp->sn_text; | |
8113 return NULL; | |
8114 } | |
8115 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8116 # if defined(FEAT_SIGN_ICONS) || defined(PROTO) |
7 | 8117 void * |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8118 sign_get_image( |
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8119 int typenr) /* the attribute which may have a sign */ |
7 | 8120 { |
8121 sign_T *sp; | |
8122 | |
8123 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8124 if (sp->sn_typenr == typenr) | |
8125 return sp->sn_image; | |
8126 return NULL; | |
8127 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8128 # endif |
7 | 8129 |
8130 /* | |
8131 * Get the name of a sign by its typenr. | |
8132 */ | |
8133 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8134 sign_typenr2name(int typenr) |
7 | 8135 { |
8136 sign_T *sp; | |
8137 | |
8138 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8139 if (sp->sn_typenr == typenr) | |
8140 return sp->sn_name; | |
8141 return (char_u *)_("[Deleted]"); | |
8142 } | |
8143 | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8144 # if defined(EXITFREE) || defined(PROTO) |
1828 | 8145 /* |
8146 * Undefine/free all signs. | |
8147 */ | |
8148 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8149 free_signs(void) |
1828 | 8150 { |
8151 while (first_sign != NULL) | |
8152 sign_undefine(first_sign, NULL); | |
8153 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8154 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8155 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8156 # if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
1868 | 8157 static enum |
8158 { | |
8159 EXP_SUBCMD, /* expand :sign sub-commands */ | |
8160 EXP_DEFINE, /* expand :sign define {name} args */ | |
8161 EXP_PLACE, /* expand :sign place {id} args */ | |
8162 EXP_UNPLACE, /* expand :sign unplace" */ | |
8163 EXP_SIGN_NAMES /* expand with name of placed signs */ | |
8164 } expand_what; | |
8165 | |
8166 /* | |
8167 * Function given to ExpandGeneric() to obtain the sign command | |
8168 * expansion. | |
8169 */ | |
8170 char_u * | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8171 get_sign_name(expand_T *xp UNUSED, int idx) |
1868 | 8172 { |
8173 sign_T *sp; | |
8174 int current_idx; | |
8175 | |
8176 switch (expand_what) | |
8177 { | |
8178 case EXP_SUBCMD: | |
8179 return (char_u *)cmds[idx]; | |
8180 case EXP_DEFINE: | |
8181 { | |
8182 char *define_arg[] = | |
8183 { | |
8184 "icon=", "linehl=", "text=", "texthl=", NULL | |
8185 }; | |
8186 return (char_u *)define_arg[idx]; | |
8187 } | |
8188 case EXP_PLACE: | |
8189 { | |
8190 char *place_arg[] = | |
8191 { | |
8192 "line=", "name=", "file=", "buffer=", NULL | |
8193 }; | |
8194 return (char_u *)place_arg[idx]; | |
8195 } | |
8196 case EXP_UNPLACE: | |
8197 { | |
8198 char *unplace_arg[] = { "file=", "buffer=", NULL }; | |
8199 return (char_u *)unplace_arg[idx]; | |
8200 } | |
8201 case EXP_SIGN_NAMES: | |
8202 /* Complete with name of signs already defined */ | |
8203 current_idx = 0; | |
8204 for (sp = first_sign; sp != NULL; sp = sp->sn_next) | |
8205 if (current_idx++ == idx) | |
8206 return sp->sn_name; | |
8207 return NULL; | |
8208 default: | |
8209 return NULL; | |
8210 } | |
8211 } | |
8212 | |
8213 /* | |
8214 * Handle command line completion for :sign command. | |
8215 */ | |
8216 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8217 set_context_in_sign_cmd(expand_T *xp, char_u *arg) |
1868 | 8218 { |
8219 char_u *p; | |
8220 char_u *end_subcmd; | |
8221 char_u *last; | |
8222 int cmd_idx; | |
8223 char_u *begin_subcmd_args; | |
8224 | |
8225 /* Default: expand subcommands. */ | |
8226 xp->xp_context = EXPAND_SIGN; | |
8227 expand_what = EXP_SUBCMD; | |
8228 xp->xp_pattern = arg; | |
8229 | |
8230 end_subcmd = skiptowhite(arg); | |
8231 if (*end_subcmd == NUL) | |
8232 /* expand subcmd name | |
8233 * :sign {subcmd}<CTRL-D>*/ | |
8234 return; | |
8235 | |
8236 cmd_idx = sign_cmd_idx(arg, end_subcmd); | |
8237 | |
8238 /* :sign {subcmd} {subcmd_args} | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8239 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8240 * begin_subcmd_args */ |
1868 | 8241 begin_subcmd_args = skipwhite(end_subcmd); |
8242 p = skiptowhite(begin_subcmd_args); | |
8243 if (*p == NUL) | |
8244 { | |
8245 /* | |
8246 * Expand first argument of subcmd when possible. | |
8247 * For ":jump {id}" and ":unplace {id}", we could | |
8248 * possibly expand the ids of all signs already placed. | |
8249 */ | |
8250 xp->xp_pattern = begin_subcmd_args; | |
8251 switch (cmd_idx) | |
8252 { | |
8253 case SIGNCMD_LIST: | |
8254 case SIGNCMD_UNDEFINE: | |
8255 /* :sign list <CTRL-D> | |
8256 * :sign undefine <CTRL-D> */ | |
8257 expand_what = EXP_SIGN_NAMES; | |
8258 break; | |
8259 default: | |
8260 xp->xp_context = EXPAND_NOTHING; | |
8261 } | |
8262 return; | |
8263 } | |
8264 | |
8265 /* expand last argument of subcmd */ | |
8266 | |
8267 /* :sign define {name} {args}... | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8268 * | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8269 * p */ |
1868 | 8270 |
8271 /* Loop until reaching last argument. */ | |
8272 do | |
8273 { | |
8274 p = skipwhite(p); | |
8275 last = p; | |
8276 p = skiptowhite(p); | |
8277 } while (*p != NUL); | |
8278 | |
8279 p = vim_strchr(last, '='); | |
8280 | |
8281 /* :sign define {name} {args}... {last}= | |
2311
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8282 * | | |
ccda151dde4e
Support completion for ":find". (Nazri Ramliy)
Bram Moolenaar <bram@vim.org>
parents:
2290
diff
changeset
|
8283 * last p */ |
10299
7b2f95633e28
commit https://github.com/vim/vim/commit/7756e7465d627ff9cd01e59625484a8c302ef853
Christian Brabandt <cb@256bit.org>
parents:
10264
diff
changeset
|
8284 if (p == NULL) |
1868 | 8285 { |
8286 /* Expand last argument name (before equal sign). */ | |
8287 xp->xp_pattern = last; | |
8288 switch (cmd_idx) | |
8289 { | |
8290 case SIGNCMD_DEFINE: | |
8291 expand_what = EXP_DEFINE; | |
8292 break; | |
8293 case SIGNCMD_PLACE: | |
8294 expand_what = EXP_PLACE; | |
8295 break; | |
8296 case SIGNCMD_JUMP: | |
8297 case SIGNCMD_UNPLACE: | |
8298 expand_what = EXP_UNPLACE; | |
8299 break; | |
8300 default: | |
8301 xp->xp_context = EXPAND_NOTHING; | |
8302 } | |
8303 } | |
8304 else | |
8305 { | |
8306 /* Expand last argument value (after equal sign). */ | |
8307 xp->xp_pattern = p + 1; | |
8308 switch (cmd_idx) | |
8309 { | |
8310 case SIGNCMD_DEFINE: | |
8311 if (STRNCMP(last, "texthl", p - last) == 0 || | |
8312 STRNCMP(last, "linehl", p - last) == 0) | |
8313 xp->xp_context = EXPAND_HIGHLIGHT; | |
8314 else if (STRNCMP(last, "icon", p - last) == 0) | |
8315 xp->xp_context = EXPAND_FILES; | |
8316 else | |
8317 xp->xp_context = EXPAND_NOTHING; | |
8318 break; | |
8319 case SIGNCMD_PLACE: | |
8320 if (STRNCMP(last, "name", p - last) == 0) | |
8321 expand_what = EXP_SIGN_NAMES; | |
8322 else | |
8323 xp->xp_context = EXPAND_NOTHING; | |
8324 break; | |
8325 default: | |
8326 xp->xp_context = EXPAND_NOTHING; | |
8327 } | |
8328 } | |
8329 } | |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8330 # endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8331 #endif |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8332 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8333 /* |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8334 * Make the user happy. |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8335 */ |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8336 void |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8337 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
|
8338 { |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8339 static char *code[] = { |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8340 "\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
|
8341 "\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
|
8342 }; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8343 char *p; |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8344 int n; |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8345 int i; |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8346 |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8347 msg_start(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8348 msg_putchar('\n'); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8349 for (i = 0; i < 2; ++i) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8350 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
|
8351 if (*p == 'x') |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8352 msg_putchar('\n'); |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8353 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8354 for (n = *p++; n > 0; --n) |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8355 if (*p == 'o' || *p == '$') |
11158
501f46f7644c
patch 8.0.0466: still macros that should be all-caps
Christian Brabandt <cb@256bit.org>
parents:
11144
diff
changeset
|
8356 msg_putchar_attr(*p, HL_ATTR(HLF_L)); |
8879
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8357 else |
cea5ff374062
commit https://github.com/vim/vim/commit/700eefe5a4385fd128f5496e3ca384869752376a
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
8358 msg_putchar(*p); |
7402
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8359 msg_clr_eos(); |
2c63e9ecf29d
commit https://github.com/vim/vim/commit/86e179dbe75010e9545e1a2fcc92a15d57bf27fd
Christian Brabandt <cb@256bit.org>
parents:
7340
diff
changeset
|
8360 } |
7 | 8361 |
8362 /* | |
8363 * ":drop" | |
8364 * Opens the first argument in a window. When there are two or more arguments | |
8365 * the argument list is redefined. | |
8366 */ | |
8367 void | |
7819
f86adafb28d4
commit https://github.com/vim/vim/commit/78c0b7d43e5048fd71d12816659667834170c76d
Christian Brabandt <cb@256bit.org>
parents:
7799
diff
changeset
|
8368 ex_drop(exarg_T *eap) |
7 | 8369 { |
8370 int split = FALSE; | |
8371 win_T *wp; | |
8372 buf_T *buf; | |
735 | 8373 tabpage_T *tp; |
7 | 8374 |
8375 /* | |
8376 * Check if the first argument is already being edited in a window. If | |
8377 * so, jump to that window. | |
8378 * We would actually need to check all arguments, but that's complicated | |
8379 * and mostly only one file is dropped. | |
8380 * This also ignores wildcards, since it is very unlikely the user is | |
8381 * editing a file name with a wildcard character. | |
8382 */ | |
735 | 8383 set_arglist(eap->arg); |
8384 | |
1067 | 8385 /* |
8386 * Expanding wildcards may result in an empty argument list. E.g. when | |
8387 * editing "foo.pyc" and ".pyc" is in 'wildignore'. Assume that we | |
8388 * already did an error message for this. | |
8389 */ | |
8390 if (ARGCOUNT == 0) | |
8391 return; | |
8392 | |
735 | 8393 if (cmdmod.tab) |
8394 { | |
8395 /* ":tab drop file ...": open a tab for each argument that isn't | |
8396 * edited in a window yet. It's like ":tab all" but without closing | |
8397 * windows or tabs. */ | |
8398 ex_all(eap); | |
8399 } | |
8400 else | |
8401 { | |
8402 /* ":drop file ...": Edit the first argument. Jump to an existing | |
8403 * window if possible, edit in current window if the current buffer | |
8404 * can be abandoned, otherwise open a new window. */ | |
8405 buf = buflist_findnr(ARGLIST[0].ae_fnum); | |
8406 | |
8407 FOR_ALL_TAB_WINDOWS(tp, wp) | |
8408 { | |
8409 if (wp->w_buffer == buf) | |
7 | 8410 { |
825 | 8411 goto_tabpage_win(tp, wp); |
7 | 8412 curwin->w_arg_idx = 0; |
8413 return; | |
8414 } | |
8415 } | |
735 | 8416 |
8417 /* | |
8418 * Check whether the current buffer is changed. If so, we will need | |
8419 * to split the current window or data could be lost. | |
8420 * Skip the check if the 'hidden' option is set, as in this case the | |
8421 * buffer won't be lost. | |
8422 */ | |
11957
bc0fee081e1e
patch 8.0.0858: can exit while a terminal is still running a job
Christian Brabandt <cb@256bit.org>
parents:
11800
diff
changeset
|
8423 if (!buf_hide(curbuf)) |
735 | 8424 { |
8425 ++emsg_off; | |
5464 | 8426 split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD); |
735 | 8427 --emsg_off; |
8428 } | |
8429 | |
8430 /* Fake a ":sfirst" or ":first" command edit the first argument. */ | |
8431 if (split) | |
8432 { | |
8433 eap->cmdidx = CMD_sfirst; | |
8434 eap->cmd[0] = 's'; | |
8435 } | |
8436 else | |
8437 eap->cmdidx = CMD_first; | |
8438 ex_rewind(eap); | |
8439 } | |
7 | 8440 } |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8441 |
9931
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 * 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
|
8444 * 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
|
8445 * 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
|
8446 * 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
|
8447 * 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
|
8448 */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8449 char_u * |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8450 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
|
8451 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8452 int c; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8453 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8454 if (vim_isIDc(*p)) |
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 /* ":vimgrep pattern fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8457 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8458 *s = p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8459 p = skiptowhite(p); |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8460 if (s != NULL && *p != NUL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8461 *p++ = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8462 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8463 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8464 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8465 /* ":vimgrep /pattern/[g][j] fname" */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8466 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8467 *s = p + 1; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8468 c = *p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8469 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
|
8470 if (*p != c) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8471 return NULL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8472 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8473 /* Truncate the pattern. */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8474 if (s != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8475 *p = NUL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8476 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8477 |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8478 /* Find the flags */ |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8479 while (*p == 'g' || *p == 'j') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8480 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8481 if (flags != NULL) |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8482 { |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8483 if (*p == 'g') |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8484 *flags |= VGR_GLOBAL; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8485 else |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8486 *flags |= VGR_NOJUMP; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8487 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8488 ++p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8489 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8490 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8491 return p; |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8492 } |
05bfc3d37efb
commit https://github.com/vim/vim/commit/9baf297c99cc35adb921bee04369499d76438889
Christian Brabandt <cb@256bit.org>
parents:
9915
diff
changeset
|
8493 |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8494 #if defined(FEAT_EVAL) || defined(PROTO) |
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 * 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
|
8497 */ |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8498 void |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8499 ex_oldfiles(exarg_T *eap UNUSED) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8500 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8501 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
|
8502 listitem_T *li; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8503 int nr = 0; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8504 char_u *fname; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8505 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8506 if (l == NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8507 msg((char_u *)_("No old files")); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8508 else |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8509 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8510 msg_start(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8511 msg_scroll = TRUE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8512 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
|
8513 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8514 ++nr; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8515 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
|
8516 if (!message_filtered(fname)) |
9915
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 msg_outnum((long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8519 MSG_PUTS(": "); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8520 msg_outtrans(fname); |
10021
5fc4bec66c33
commit https://github.com/vim/vim/commit/885c00eabe6d1fd757d4f0eb531ad3a15a35ec04
Christian Brabandt <cb@256bit.org>
parents:
9980
diff
changeset
|
8521 msg_clr_eos(); |
9915
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8522 msg_putchar('\n'); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8523 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
|
8524 ui_breakcheck(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8525 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8526 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8527 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8528 /* 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
|
8529 got_int = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8530 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8531 # ifdef FEAT_BROWSE_CMD |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8532 if (cmdmod.browse) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8533 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8534 quit_more = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8535 nr = prompt_for_number(FALSE); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8536 msg_starthere(); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8537 if (nr > 0) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8538 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8539 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
|
8540 (long)nr); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8541 |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8542 if (p != NULL) |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8543 { |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8544 p = expand_env_save(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8545 eap->arg = p; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8546 eap->cmdidx = CMD_edit; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8547 cmdmod.browse = FALSE; |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8548 do_exedit(eap, NULL); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8549 vim_free(p); |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8550 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8551 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8552 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8553 # endif |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8554 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8555 } |
4da1a3879100
commit https://github.com/vim/vim/commit/e11d61a3b1cdedf3144de697a2b38af62c3a78d8
Christian Brabandt <cb@256bit.org>
parents:
9902
diff
changeset
|
8556 #endif |