blob: 9ebc9c24c48de86f9dbcadcdac064ce89ff0d028 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
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 * mark.c: functions for setting marks and jumping to them
12 */
13
14#include "vim.h"
15
16/*
17 * This file contains routines to maintain and manipulate marks.
18 */
19
20/*
21 * If a named file mark's lnum is non-zero, it is valid.
22 * If a named file mark's fnum is non-zero, it is for an existing buffer,
23 * otherwise it is from .viminfo and namedfm[n].fname is the file name.
24 * There are marks 'A - 'Z (set by user) and '0 to '9 (set when writing
25 * viminfo).
26 */
27#define EXTRA_MARKS 10 /* marks 0-9 */
28static xfmark_T namedfm[NMARKS + EXTRA_MARKS]; /* marks with file nr */
29
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +010030static void fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf);
31static char_u *mark_line(pos_T *mp, int lead_len);
32static void show_one_mark(int, char_u *, pos_T *, char_u *, int current);
Bram Moolenaar071d4272004-06-13 20:20:40 +000033#ifdef FEAT_VIMINFO
Bram Moolenaar92b8b2d2016-01-29 22:36:45 +010034static void write_one_filemark(FILE *fp, xfmark_T *fm, int c1, int c2);
Bram Moolenaar071d4272004-06-13 20:20:40 +000035#endif
Bram Moolenaar88d298a2017-03-14 21:53:58 +010036static void mark_adjust_internal(linenr_T line1, linenr_T line2, long amount,
37 long amount_after, int adjust_folds);
Bram Moolenaar071d4272004-06-13 20:20:40 +000038
39/*
Bram Moolenaarbfb2d402006-03-03 22:50:42 +000040 * Set named mark "c" at current cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +000041 * Returns OK on success, FAIL if bad name given.
42 */
43 int
Bram Moolenaar52ea13d2016-01-30 18:51:09 +010044setmark(int c)
Bram Moolenaar071d4272004-06-13 20:20:40 +000045{
Bram Moolenaarbfb2d402006-03-03 22:50:42 +000046 return setmark_pos(c, &curwin->w_cursor, curbuf->b_fnum);
47}
48
49/*
50 * Set named mark "c" to position "pos".
51 * When "c" is upper case use file "fnum".
52 * Returns OK on success, FAIL if bad name given.
53 */
54 int
Bram Moolenaar52ea13d2016-01-30 18:51:09 +010055setmark_pos(int c, pos_T *pos, int fnum)
Bram Moolenaarbfb2d402006-03-03 22:50:42 +000056{
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 int i;
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010058 buf_T *buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +000059
60 /* Check for a special key (may cause islower() to crash). */
61 if (c < 0)
62 return FAIL;
63
64 if (c == '\'' || c == '`')
65 {
Bram Moolenaarbfb2d402006-03-03 22:50:42 +000066 if (pos == &curwin->w_cursor)
67 {
68 setpcmark();
69 /* keep it even when the cursor doesn't move */
70 curwin->w_prev_pcmark = curwin->w_pcmark;
71 }
72 else
73 curwin->w_pcmark = *pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +000074 return OK;
75 }
76
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010077 buf = buflist_findnr(fnum);
78 if (buf == NULL)
79 return FAIL;
80
Bram Moolenaar08250432008-02-13 11:42:46 +000081 if (c == '"')
82 {
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010083 buf->b_last_cursor = *pos;
Bram Moolenaar08250432008-02-13 11:42:46 +000084 return OK;
85 }
86
Bram Moolenaar071d4272004-06-13 20:20:40 +000087 /* Allow setting '[ and '] for an autocommand that simulates reading a
88 * file. */
89 if (c == '[')
90 {
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010091 buf->b_op_start = *pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 return OK;
93 }
94 if (c == ']')
95 {
Bram Moolenaarf13e00b2017-01-28 18:23:54 +010096 buf->b_op_end = *pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +000097 return OK;
98 }
99
Bram Moolenaarbc88a272013-08-02 17:22:23 +0200100 if (c == '<' || c == '>')
Bram Moolenaar0306ac32012-07-06 17:51:28 +0200101 {
Bram Moolenaarbc88a272013-08-02 17:22:23 +0200102 if (c == '<')
Bram Moolenaarf13e00b2017-01-28 18:23:54 +0100103 buf->b_visual.vi_start = *pos;
Bram Moolenaarbc88a272013-08-02 17:22:23 +0200104 else
Bram Moolenaarf13e00b2017-01-28 18:23:54 +0100105 buf->b_visual.vi_end = *pos;
106 if (buf->b_visual.vi_mode == NUL)
Bram Moolenaarbc88a272013-08-02 17:22:23 +0200107 /* Visual_mode has not yet been set, use a sane default. */
Bram Moolenaarf13e00b2017-01-28 18:23:54 +0100108 buf->b_visual.vi_mode = 'v';
Bram Moolenaar0306ac32012-07-06 17:51:28 +0200109 return OK;
110 }
Bram Moolenaar0306ac32012-07-06 17:51:28 +0200111
Bram Moolenaar2d358992016-06-12 21:20:54 +0200112 if (ASCII_ISLOWER(c))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113 {
114 i = c - 'a';
Bram Moolenaarf13e00b2017-01-28 18:23:54 +0100115 buf->b_namedm[i] = *pos;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116 return OK;
117 }
Bram Moolenaar2d358992016-06-12 21:20:54 +0200118 if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000119 {
Bram Moolenaar2d358992016-06-12 21:20:54 +0200120 if (VIM_ISDIGIT(c))
121 i = c - '0' + NMARKS;
122 else
123 i = c - 'A';
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000124 namedfm[i].fmark.mark = *pos;
125 namedfm[i].fmark.fnum = fnum;
Bram Moolenaard23a8232018-02-10 18:45:26 +0100126 VIM_CLEAR(namedfm[i].fname);
Bram Moolenaar2d358992016-06-12 21:20:54 +0200127#ifdef FEAT_VIMINFO
128 namedfm[i].time_set = vim_time();
129#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000130 return OK;
131 }
132 return FAIL;
133}
134
135/*
136 * Set the previous context mark to the current position and add it to the
137 * jump list.
138 */
139 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100140setpcmark(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141{
142#ifdef FEAT_JUMPLIST
143 int i;
144 xfmark_T *fm;
145#endif
146#ifdef JUMPLIST_ROTATE
147 xfmark_T tempmark;
148#endif
149
150 /* for :global the mark is set only once */
151 if (global_busy || listcmd_busy || cmdmod.keepjumps)
152 return;
153
154 curwin->w_prev_pcmark = curwin->w_pcmark;
155 curwin->w_pcmark = curwin->w_cursor;
156
157#ifdef FEAT_JUMPLIST
158# ifdef JUMPLIST_ROTATE
159 /*
160 * If last used entry is not at the top, put it at the top by rotating
161 * the stack until it is (the newer entries will be at the bottom).
162 * Keep one entry (the last used one) at the top.
163 */
164 if (curwin->w_jumplistidx < curwin->w_jumplistlen)
165 ++curwin->w_jumplistidx;
166 while (curwin->w_jumplistidx < curwin->w_jumplistlen)
167 {
168 tempmark = curwin->w_jumplist[curwin->w_jumplistlen - 1];
169 for (i = curwin->w_jumplistlen - 1; i > 0; --i)
170 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1];
171 curwin->w_jumplist[0] = tempmark;
172 ++curwin->w_jumplistidx;
173 }
174# endif
175
176 /* If jumplist is full: remove oldest entry */
177 if (++curwin->w_jumplistlen > JUMPLISTSIZE)
178 {
179 curwin->w_jumplistlen = JUMPLISTSIZE;
180 vim_free(curwin->w_jumplist[0].fname);
181 for (i = 1; i < JUMPLISTSIZE; ++i)
182 curwin->w_jumplist[i - 1] = curwin->w_jumplist[i];
183 }
184 curwin->w_jumplistidx = curwin->w_jumplistlen;
185 fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
186
187 fm->fmark.mark = curwin->w_pcmark;
188 fm->fmark.fnum = curbuf->b_fnum;
189 fm->fname = NULL;
Bram Moolenaar2d358992016-06-12 21:20:54 +0200190# ifdef FEAT_VIMINFO
191 fm->time_set = vim_time();
192# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000193#endif
194}
195
196/*
197 * To change context, call setpcmark(), then move the current position to
198 * where ever, then call checkpcmark(). This ensures that the previous
199 * context will only be changed if the cursor moved to a different line.
200 * If pcmark was deleted (with "dG") the previous mark is restored.
201 */
202 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100203checkpcmark(void)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000204{
205 if (curwin->w_prev_pcmark.lnum != 0
Bram Moolenaarb5aedf32017-03-12 18:23:53 +0100206 && (EQUAL_POS(curwin->w_pcmark, curwin->w_cursor)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207 || curwin->w_pcmark.lnum == 0))
208 {
209 curwin->w_pcmark = curwin->w_prev_pcmark;
210 curwin->w_prev_pcmark.lnum = 0; /* Show it has been checked */
211 }
212}
213
214#if defined(FEAT_JUMPLIST) || defined(PROTO)
215/*
216 * move "count" positions in the jump list (count may be negative)
217 */
218 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100219movemark(int count)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000220{
221 pos_T *pos;
222 xfmark_T *jmp;
223
Bram Moolenaara7e18d22018-02-11 14:29:49 +0100224 cleanup_jumplist(curwin);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225
226 if (curwin->w_jumplistlen == 0) /* nothing to jump to */
227 return (pos_T *)NULL;
228
229 for (;;)
230 {
231 if (curwin->w_jumplistidx + count < 0
232 || curwin->w_jumplistidx + count >= curwin->w_jumplistlen)
233 return (pos_T *)NULL;
234
235 /*
236 * if first CTRL-O or CTRL-I command after a jump, add cursor position
Bram Moolenaarf711faf2007-05-10 16:48:19 +0000237 * to list. Careful: If there are duplicates (CTRL-O immediately after
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238 * starting Vim on a file), another entry may have been removed.
239 */
240 if (curwin->w_jumplistidx == curwin->w_jumplistlen)
241 {
242 setpcmark();
243 --curwin->w_jumplistidx; /* skip the new entry */
244 if (curwin->w_jumplistidx + count < 0)
245 return (pos_T *)NULL;
246 }
247
248 curwin->w_jumplistidx += count;
249
250 jmp = curwin->w_jumplist + curwin->w_jumplistidx;
251 if (jmp->fmark.fnum == 0)
252 fname2fnum(jmp);
253 if (jmp->fmark.fnum != curbuf->b_fnum)
254 {
255 /* jump to other file */
256 if (buflist_findnr(jmp->fmark.fnum) == NULL)
257 { /* Skip this one .. */
258 count += count < 0 ? -1 : 1;
259 continue;
260 }
261 if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum,
262 0, FALSE) == FAIL)
263 return (pos_T *)NULL;
264 /* Set lnum again, autocommands my have changed it */
265 curwin->w_cursor = jmp->fmark.mark;
266 pos = (pos_T *)-1;
267 }
268 else
269 pos = &(jmp->fmark.mark);
270 return pos;
271 }
272}
273
274/*
275 * Move "count" positions in the changelist (count may be negative).
276 */
277 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100278movechangelist(int count)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279{
280 int n;
281
282 if (curbuf->b_changelistlen == 0) /* nothing to jump to */
283 return (pos_T *)NULL;
284
285 n = curwin->w_changelistidx;
286 if (n + count < 0)
287 {
288 if (n == 0)
289 return (pos_T *)NULL;
290 n = 0;
291 }
292 else if (n + count >= curbuf->b_changelistlen)
293 {
294 if (n == curbuf->b_changelistlen - 1)
295 return (pos_T *)NULL;
296 n = curbuf->b_changelistlen - 1;
297 }
298 else
299 n += count;
300 curwin->w_changelistidx = n;
301 return curbuf->b_changelist + n;
302}
303#endif
304
305/*
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100306 * Find mark "c" in buffer pointed to by "buf".
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000307 * If "changefile" is TRUE it's allowed to edit another file for '0, 'A, etc.
308 * If "fnum" is not NULL store the fnum there for '0, 'A etc., don't edit
309 * another file.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310 * Returns:
311 * - pointer to pos_T if found. lnum is 0 when mark not set, -1 when mark is
312 * in another file which can't be gotten. (caller needs to check lnum!)
313 * - NULL if there is no mark called 'c'.
314 * - -1 if mark is in other file and jumped there (only if changefile is TRUE)
315 */
316 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100317getmark_buf(buf_T *buf, int c, int changefile)
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100318{
319 return getmark_buf_fnum(buf, c, changefile, NULL);
320}
321
322 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100323getmark(int c, int changefile)
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000324{
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100325 return getmark_buf_fnum(curbuf, c, changefile, NULL);
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000326}
327
328 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100329getmark_buf_fnum(
330 buf_T *buf,
331 int c,
332 int changefile,
333 int *fnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000334{
335 pos_T *posp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000336 pos_T *startp, *endp;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000337 static pos_T pos_copy;
338
339 posp = NULL;
340
341 /* Check for special key, can't be a mark name and might cause islower()
342 * to crash. */
343 if (c < 0)
344 return posp;
345#ifndef EBCDIC
346 if (c > '~') /* check for islower()/isupper() */
347 ;
348 else
349#endif
350 if (c == '\'' || c == '`') /* previous context mark */
351 {
352 pos_copy = curwin->w_pcmark; /* need to make a copy because */
353 posp = &pos_copy; /* w_pcmark may be changed soon */
354 }
355 else if (c == '"') /* to pos when leaving buffer */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100356 posp = &(buf->b_last_cursor);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000357 else if (c == '^') /* to where Insert mode stopped */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100358 posp = &(buf->b_last_insert);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000359 else if (c == '.') /* to where last change was made */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100360 posp = &(buf->b_last_change);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000361 else if (c == '[') /* to start of previous operator */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100362 posp = &(buf->b_op_start);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000363 else if (c == ']') /* to end of previous operator */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100364 posp = &(buf->b_op_end);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000365 else if (c == '{' || c == '}') /* to previous/next paragraph */
366 {
367 pos_T pos;
368 oparg_T oa;
369 int slcb = listcmd_busy;
370
371 pos = curwin->w_cursor;
372 listcmd_busy = TRUE; /* avoid that '' is changed */
Bram Moolenaar8b96d642005-09-05 22:05:30 +0000373 if (findpar(&oa.inclusive,
374 c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000375 {
376 pos_copy = curwin->w_cursor;
377 posp = &pos_copy;
378 }
379 curwin->w_cursor = pos;
380 listcmd_busy = slcb;
381 }
382 else if (c == '(' || c == ')') /* to previous/next sentence */
383 {
384 pos_T pos;
385 int slcb = listcmd_busy;
386
387 pos = curwin->w_cursor;
388 listcmd_busy = TRUE; /* avoid that '' is changed */
389 if (findsent(c == ')' ? FORWARD : BACKWARD, 1L))
390 {
391 pos_copy = curwin->w_cursor;
392 posp = &pos_copy;
393 }
394 curwin->w_cursor = pos;
395 listcmd_busy = slcb;
396 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000397 else if (c == '<' || c == '>') /* start/end of visual area */
398 {
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100399 startp = &buf->b_visual.vi_start;
400 endp = &buf->b_visual.vi_end;
Bram Moolenaarb5aedf32017-03-12 18:23:53 +0100401 if (((c == '<') == LT_POS(*startp, *endp) || endp->lnum == 0)
Bram Moolenaarf13e00b2017-01-28 18:23:54 +0100402 && startp->lnum != 0)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000403 posp = startp;
404 else
405 posp = endp;
406 /*
407 * For Visual line mode, set mark at begin or end of line
408 */
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100409 if (buf->b_visual.vi_mode == 'V')
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410 {
411 pos_copy = *posp;
412 posp = &pos_copy;
413 if (c == '<')
414 pos_copy.col = 0;
415 else
416 pos_copy.col = MAXCOL;
417#ifdef FEAT_VIRTUALEDIT
418 pos_copy.coladd = 0;
419#endif
420 }
421 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000422 else if (ASCII_ISLOWER(c)) /* normal named mark */
423 {
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100424 posp = &(buf->b_namedm[c - 'a']);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000425 }
426 else if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) /* named file mark */
427 {
428 if (VIM_ISDIGIT(c))
429 c = c - '0' + NMARKS;
430 else
431 c -= 'A';
432 posp = &(namedfm[c].fmark.mark);
433
434 if (namedfm[c].fmark.fnum == 0)
435 fname2fnum(&namedfm[c]);
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000436
437 if (fnum != NULL)
438 *fnum = namedfm[c].fmark.fnum;
Bram Moolenaar9d182dd2013-01-23 15:53:15 +0100439 else if (namedfm[c].fmark.fnum != buf->b_fnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000440 {
Bram Moolenaarbfb2d402006-03-03 22:50:42 +0000441 /* mark is in another file */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000442 posp = &pos_copy;
443
Bram Moolenaar071d4272004-06-13 20:20:40 +0000444 if (namedfm[c].fmark.mark.lnum != 0
445 && changefile && namedfm[c].fmark.fnum)
446 {
447 if (buflist_getfile(namedfm[c].fmark.fnum,
448 (linenr_T)1, GETF_SETMARK, FALSE) == OK)
449 {
450 /* Set the lnum now, autocommands could have changed it */
451 curwin->w_cursor = namedfm[c].fmark.mark;
452 return (pos_T *)-1;
453 }
454 pos_copy.lnum = -1; /* can't get file */
455 }
456 else
457 pos_copy.lnum = 0; /* mark exists, but is not valid in
458 current buffer */
459 }
460 }
461
462 return posp;
463}
464
465/*
466 * Search for the next named mark in the current file.
467 *
468 * Returns pointer to pos_T of the next mark or NULL if no mark is found.
469 */
470 pos_T *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100471getnextmark(
472 pos_T *startpos, /* where to start */
473 int dir, /* direction for search */
474 int begin_line)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000475{
476 int i;
477 pos_T *result = NULL;
478 pos_T pos;
479
480 pos = *startpos;
481
482 /* When searching backward and leaving the cursor on the first non-blank,
483 * position must be in a previous line.
484 * When searching forward and leaving the cursor on the first non-blank,
485 * position must be in a next line. */
486 if (dir == BACKWARD && begin_line)
487 pos.col = 0;
488 else if (dir == FORWARD && begin_line)
489 pos.col = MAXCOL;
490
491 for (i = 0; i < NMARKS; i++)
492 {
493 if (curbuf->b_namedm[i].lnum > 0)
494 {
495 if (dir == FORWARD)
496 {
Bram Moolenaarb5aedf32017-03-12 18:23:53 +0100497 if ((result == NULL || LT_POS(curbuf->b_namedm[i], *result))
498 && LT_POS(pos, curbuf->b_namedm[i]))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 result = &curbuf->b_namedm[i];
500 }
501 else
502 {
Bram Moolenaarb5aedf32017-03-12 18:23:53 +0100503 if ((result == NULL || LT_POS(*result, curbuf->b_namedm[i]))
504 && LT_POS(curbuf->b_namedm[i], pos))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000505 result = &curbuf->b_namedm[i];
506 }
507 }
508 }
509
510 return result;
511}
512
513/*
514 * For an xtended filemark: set the fnum from the fname.
515 * This is used for marks obtained from the .viminfo file. It's postponed
516 * until the mark is used to avoid a long startup delay.
517 */
Bram Moolenaara7e18d22018-02-11 14:29:49 +0100518 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100519fname2fnum(xfmark_T *fm)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000520{
521 char_u *p;
522
523 if (fm->fname != NULL)
524 {
525 /*
526 * First expand "~/" in the file name to the home directory.
Bram Moolenaar525ad4d2008-01-03 19:22:13 +0000527 * Don't expand the whole name, it may contain other '~' chars.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000528 */
Bram Moolenaar525ad4d2008-01-03 19:22:13 +0000529 if (fm->fname[0] == '~' && (fm->fname[1] == '/'
530#ifdef BACKSLASH_IN_FILENAME
531 || fm->fname[1] == '\\'
532#endif
533 ))
534 {
535 int len;
536
537 expand_env((char_u *)"~/", NameBuff, MAXPATHL);
Bram Moolenaarcb4cef22008-03-16 15:04:34 +0000538 len = (int)STRLEN(NameBuff);
Bram Moolenaar525ad4d2008-01-03 19:22:13 +0000539 vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1);
540 }
541 else
542 vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1);
543
544 /* Try to shorten the file name. */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000545 mch_dirname(IObuff, IOSIZE);
546 p = shorten_fname(NameBuff, IObuff);
547
548 /* buflist_new() will call fmarks_check_names() */
549 (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
550 }
551}
552
553/*
554 * Check all file marks for a name that matches the file name in buf.
555 * May replace the name with an fnum.
556 * Used for marks that come from the .viminfo file.
557 */
558 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100559fmarks_check_names(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000560{
561 char_u *name;
562 int i;
563#ifdef FEAT_JUMPLIST
564 win_T *wp;
565#endif
566
567 if (buf->b_ffname == NULL)
568 return;
569
570 name = home_replace_save(buf, buf->b_ffname);
571 if (name == NULL)
572 return;
573
574 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
575 fmarks_check_one(&namedfm[i], name, buf);
576
577#ifdef FEAT_JUMPLIST
578 FOR_ALL_WINDOWS(wp)
579 {
580 for (i = 0; i < wp->w_jumplistlen; ++i)
581 fmarks_check_one(&wp->w_jumplist[i], name, buf);
582 }
583#endif
584
585 vim_free(name);
586}
587
588 static void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100589fmarks_check_one(xfmark_T *fm, char_u *name, buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000590{
591 if (fm->fmark.fnum == 0
592 && fm->fname != NULL
593 && fnamecmp(name, fm->fname) == 0)
594 {
595 fm->fmark.fnum = buf->b_fnum;
Bram Moolenaard23a8232018-02-10 18:45:26 +0100596 VIM_CLEAR(fm->fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000597 }
598}
599
600/*
601 * Check a if a position from a mark is valid.
602 * Give and error message and return FAIL if not.
603 */
604 int
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100605check_mark(pos_T *pos)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606{
607 if (pos == NULL)
608 {
609 EMSG(_(e_umark));
610 return FAIL;
611 }
612 if (pos->lnum <= 0)
613 {
614 /* lnum is negative if mark is in another file can can't get that
615 * file, error message already give then. */
616 if (pos->lnum == 0)
617 EMSG(_(e_marknotset));
618 return FAIL;
619 }
620 if (pos->lnum > curbuf->b_ml.ml_line_count)
621 {
622 EMSG(_(e_markinval));
623 return FAIL;
624 }
625 return OK;
626}
627
628/*
629 * clrallmarks() - clear all marks in the buffer 'buf'
630 *
631 * Used mainly when trashing the entire buffer during ":e" type commands
632 */
633 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100634clrallmarks(buf_T *buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000635{
636 static int i = -1;
637
638 if (i == -1) /* first call ever: initialize */
639 for (i = 0; i < NMARKS + 1; i++)
640 {
641 namedfm[i].fmark.mark.lnum = 0;
642 namedfm[i].fname = NULL;
Bram Moolenaar2d358992016-06-12 21:20:54 +0200643#ifdef FEAT_VIMINFO
644 namedfm[i].time_set = 0;
645#endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000646 }
647
648 for (i = 0; i < NMARKS; i++)
649 buf->b_namedm[i].lnum = 0;
650 buf->b_op_start.lnum = 0; /* start/end op mark cleared */
651 buf->b_op_end.lnum = 0;
652 buf->b_last_cursor.lnum = 1; /* '" mark cleared */
653 buf->b_last_cursor.col = 0;
654#ifdef FEAT_VIRTUALEDIT
655 buf->b_last_cursor.coladd = 0;
656#endif
657 buf->b_last_insert.lnum = 0; /* '^ mark cleared */
658 buf->b_last_change.lnum = 0; /* '. mark cleared */
659#ifdef FEAT_JUMPLIST
660 buf->b_changelistlen = 0;
661#endif
662}
663
664/*
665 * Get name of file from a filemark.
666 * When it's in the current buffer, return the text at the mark.
667 * Returns an allocated string.
668 */
669 char_u *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100670fm_getname(fmark_T *fmark, int lead_len)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000671{
672 if (fmark->fnum == curbuf->b_fnum) /* current buffer */
673 return mark_line(&(fmark->mark), lead_len);
674 return buflist_nr2name(fmark->fnum, FALSE, TRUE);
675}
676
677/*
678 * Return the line at mark "mp". Truncate to fit in window.
679 * The returned string has been allocated.
680 */
681 static char_u *
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100682mark_line(pos_T *mp, int lead_len)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000683{
684 char_u *s, *p;
685 int len;
686
687 if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
688 return vim_strsave((char_u *)"-invalid-");
689 s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns);
690 if (s == NULL)
691 return NULL;
692 /* Truncate the line to fit it in the window */
693 len = 0;
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100694 for (p = s; *p != NUL; MB_PTR_ADV(p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000695 {
696 len += ptr2cells(p);
697 if (len >= Columns - lead_len)
698 break;
Bram Moolenaar071d4272004-06-13 20:20:40 +0000699 }
700 *p = NUL;
701 return s;
702}
703
704/*
705 * print the marks
706 */
707 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100708do_marks(exarg_T *eap)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000709{
710 char_u *arg = eap->arg;
711 int i;
712 char_u *name;
713
714 if (arg != NULL && *arg == NUL)
715 arg = NULL;
716
717 show_one_mark('\'', arg, &curwin->w_pcmark, NULL, TRUE);
718 for (i = 0; i < NMARKS; ++i)
719 show_one_mark(i + 'a', arg, &curbuf->b_namedm[i], NULL, TRUE);
720 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
721 {
722 if (namedfm[i].fmark.fnum != 0)
723 name = fm_getname(&namedfm[i].fmark, 15);
724 else
725 name = namedfm[i].fname;
726 if (name != NULL)
727 {
728 show_one_mark(i >= NMARKS ? i - NMARKS + '0' : i + 'A',
729 arg, &namedfm[i].fmark.mark, name,
730 namedfm[i].fmark.fnum == curbuf->b_fnum);
731 if (namedfm[i].fmark.fnum != 0)
732 vim_free(name);
733 }
734 }
735 show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE);
736 show_one_mark('[', arg, &curbuf->b_op_start, NULL, TRUE);
737 show_one_mark(']', arg, &curbuf->b_op_end, NULL, TRUE);
738 show_one_mark('^', arg, &curbuf->b_last_insert, NULL, TRUE);
739 show_one_mark('.', arg, &curbuf->b_last_change, NULL, TRUE);
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000740 show_one_mark('<', arg, &curbuf->b_visual.vi_start, NULL, TRUE);
741 show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, TRUE);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000742 show_one_mark(-1, arg, NULL, NULL, FALSE);
743}
744
745 static void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100746show_one_mark(
747 int c,
748 char_u *arg,
749 pos_T *p,
750 char_u *name,
751 int current) /* in current file */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000752{
753 static int did_title = FALSE;
754 int mustfree = FALSE;
755
756 if (c == -1) /* finish up */
757 {
758 if (did_title)
759 did_title = FALSE;
760 else
761 {
762 if (arg == NULL)
763 MSG(_("No marks set"));
764 else
765 EMSG2(_("E283: No marks matching \"%s\""), arg);
766 }
767 }
768 /* don't output anything if 'q' typed at --more-- prompt */
769 else if (!got_int
770 && (arg == NULL || vim_strchr(arg, c) != NULL)
771 && p->lnum != 0)
772 {
773 if (!did_title)
774 {
775 /* Highlight title */
776 MSG_PUTS_TITLE(_("\nmark line col file/text"));
777 did_title = TRUE;
778 }
779 msg_putchar('\n');
780 if (!got_int)
781 {
782 sprintf((char *)IObuff, " %c %6ld %4d ", c, p->lnum, p->col);
783 msg_outtrans(IObuff);
784 if (name == NULL && current)
785 {
786 name = mark_line(p, 15);
787 mustfree = TRUE;
788 }
789 if (name != NULL)
790 {
Bram Moolenaar8820b482017-03-16 17:23:31 +0100791 msg_outtrans_attr(name, current ? HL_ATTR(HLF_D) : 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000792 if (mustfree)
793 vim_free(name);
794 }
795 }
796 out_flush(); /* show one line at a time */
797 }
798}
799
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000800/*
801 * ":delmarks[!] [marks]"
802 */
803 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100804ex_delmarks(exarg_T *eap)
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000805{
806 char_u *p;
807 int from, to;
808 int i;
809 int lower;
810 int digit;
811 int n;
812
813 if (*eap->arg == NUL && eap->forceit)
814 /* clear all marks */
815 clrallmarks(curbuf);
816 else if (eap->forceit)
817 EMSG(_(e_invarg));
818 else if (*eap->arg == NUL)
819 EMSG(_(e_argreq));
820 else
821 {
822 /* clear specified marks only */
823 for (p = eap->arg; *p != NUL; ++p)
824 {
825 lower = ASCII_ISLOWER(*p);
826 digit = VIM_ISDIGIT(*p);
827 if (lower || digit || ASCII_ISUPPER(*p))
828 {
829 if (p[1] == '-')
830 {
831 /* clear range of marks */
832 from = *p;
833 to = p[2];
834 if (!(lower ? ASCII_ISLOWER(p[2])
835 : (digit ? VIM_ISDIGIT(p[2])
836 : ASCII_ISUPPER(p[2])))
837 || to < from)
838 {
839 EMSG2(_(e_invarg2), p);
840 return;
841 }
842 p += 2;
843 }
844 else
845 /* clear one lower case mark */
846 from = to = *p;
847
848 for (i = from; i <= to; ++i)
849 {
850 if (lower)
851 curbuf->b_namedm[i - 'a'].lnum = 0;
852 else
853 {
854 if (digit)
855 n = i - '0' + NMARKS;
856 else
857 n = i - 'A';
858 namedfm[n].fmark.mark.lnum = 0;
Bram Moolenaard23a8232018-02-10 18:45:26 +0100859 VIM_CLEAR(namedfm[n].fname);
Bram Moolenaar2d358992016-06-12 21:20:54 +0200860#ifdef FEAT_VIMINFO
861 namedfm[n].time_set = 0;
862#endif
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000863 }
864 }
865 }
866 else
867 switch (*p)
868 {
869 case '"': curbuf->b_last_cursor.lnum = 0; break;
870 case '^': curbuf->b_last_insert.lnum = 0; break;
871 case '.': curbuf->b_last_change.lnum = 0; break;
872 case '[': curbuf->b_op_start.lnum = 0; break;
873 case ']': curbuf->b_op_end.lnum = 0; break;
Bram Moolenaara226a6d2006-02-26 23:59:20 +0000874 case '<': curbuf->b_visual.vi_start.lnum = 0; break;
875 case '>': curbuf->b_visual.vi_end.lnum = 0; break;
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000876 case ' ': break;
877 default: EMSG2(_(e_invarg2), p);
878 return;
879 }
880 }
881 }
882}
883
Bram Moolenaar071d4272004-06-13 20:20:40 +0000884#if defined(FEAT_JUMPLIST) || defined(PROTO)
885/*
886 * print the jumplist
887 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000888 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100889ex_jumps(exarg_T *eap UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000890{
891 int i;
892 char_u *name;
893
Bram Moolenaara7e18d22018-02-11 14:29:49 +0100894 cleanup_jumplist(curwin);
895
Bram Moolenaar071d4272004-06-13 20:20:40 +0000896 /* Highlight title */
897 MSG_PUTS_TITLE(_("\n jump line col file/text"));
898 for (i = 0; i < curwin->w_jumplistlen && !got_int; ++i)
899 {
900 if (curwin->w_jumplist[i].fmark.mark.lnum != 0)
901 {
902 if (curwin->w_jumplist[i].fmark.fnum == 0)
903 fname2fnum(&curwin->w_jumplist[i]);
904 name = fm_getname(&curwin->w_jumplist[i].fmark, 16);
905 if (name == NULL) /* file name not available */
906 continue;
907
908 msg_putchar('\n');
909 if (got_int)
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000910 {
911 vim_free(name);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000912 break;
Bram Moolenaared39e1d2008-08-09 17:55:22 +0000913 }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000914 sprintf((char *)IObuff, "%c %2d %5ld %4d ",
915 i == curwin->w_jumplistidx ? '>' : ' ',
916 i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
917 : curwin->w_jumplistidx - i,
918 curwin->w_jumplist[i].fmark.mark.lnum,
919 curwin->w_jumplist[i].fmark.mark.col);
920 msg_outtrans(IObuff);
921 msg_outtrans_attr(name,
922 curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
Bram Moolenaar8820b482017-03-16 17:23:31 +0100923 ? HL_ATTR(HLF_D) : 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +0000924 vim_free(name);
925 ui_breakcheck();
926 }
927 out_flush();
928 }
929 if (curwin->w_jumplistidx == curwin->w_jumplistlen)
930 MSG_PUTS("\n>");
931}
932
Bram Moolenaar2d358992016-06-12 21:20:54 +0200933 void
934ex_clearjumps(exarg_T *eap UNUSED)
935{
936 free_jumplist(curwin);
937 curwin->w_jumplistlen = 0;
938 curwin->w_jumplistidx = 0;
939}
940
Bram Moolenaar071d4272004-06-13 20:20:40 +0000941/*
942 * print the changelist
943 */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000944 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +0100945ex_changes(exarg_T *eap UNUSED)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000946{
947 int i;
948 char_u *name;
949
950 /* Highlight title */
951 MSG_PUTS_TITLE(_("\nchange line col text"));
952
953 for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i)
954 {
955 if (curbuf->b_changelist[i].lnum != 0)
956 {
957 msg_putchar('\n');
958 if (got_int)
959 break;
960 sprintf((char *)IObuff, "%c %3d %5ld %4d ",
961 i == curwin->w_changelistidx ? '>' : ' ',
962 i > curwin->w_changelistidx ? i - curwin->w_changelistidx
963 : curwin->w_changelistidx - i,
964 (long)curbuf->b_changelist[i].lnum,
965 curbuf->b_changelist[i].col);
966 msg_outtrans(IObuff);
967 name = mark_line(&curbuf->b_changelist[i], 17);
968 if (name == NULL)
969 break;
Bram Moolenaar8820b482017-03-16 17:23:31 +0100970 msg_outtrans_attr(name, HL_ATTR(HLF_D));
Bram Moolenaar071d4272004-06-13 20:20:40 +0000971 vim_free(name);
972 ui_breakcheck();
973 }
974 out_flush();
975 }
976 if (curwin->w_changelistidx == curbuf->b_changelistlen)
977 MSG_PUTS("\n>");
978}
979#endif
980
981#define one_adjust(add) \
982 { \
983 lp = add; \
984 if (*lp >= line1 && *lp <= line2) \
985 { \
986 if (amount == MAXLNUM) \
987 *lp = 0; \
988 else \
989 *lp += amount; \
990 } \
991 else if (amount_after && *lp > line2) \
992 *lp += amount_after; \
993 }
994
995/* don't delete the line, just put at first deleted line */
996#define one_adjust_nodel(add) \
997 { \
998 lp = add; \
999 if (*lp >= line1 && *lp <= line2) \
1000 { \
1001 if (amount == MAXLNUM) \
1002 *lp = line1; \
1003 else \
1004 *lp += amount; \
1005 } \
1006 else if (amount_after && *lp > line2) \
1007 *lp += amount_after; \
1008 }
1009
1010/*
1011 * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines.
1012 * Must be called before changed_*(), appended_lines() or deleted_lines().
1013 * May be called before or after changing the text.
1014 * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks
1015 * within this range are made invalid.
1016 * If 'amount_after' is non-zero adjust marks after line2.
1017 * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2);
1018 * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
1019 * or: mark_adjust(56, 55, MAXLNUM, 2);
1020 */
1021 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001022mark_adjust(
1023 linenr_T line1,
1024 linenr_T line2,
1025 long amount,
1026 long amount_after)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001027{
Bram Moolenaar88d298a2017-03-14 21:53:58 +01001028 mark_adjust_internal(line1, line2, amount, amount_after, TRUE);
1029}
1030
1031 void
1032mark_adjust_nofold(
1033 linenr_T line1,
1034 linenr_T line2,
1035 long amount,
1036 long amount_after)
1037{
1038 mark_adjust_internal(line1, line2, amount, amount_after, FALSE);
1039}
1040
1041 static void
1042mark_adjust_internal(
1043 linenr_T line1,
1044 linenr_T line2,
1045 long amount,
1046 long amount_after,
1047 int adjust_folds UNUSED)
1048{
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 int i;
1050 int fnum = curbuf->b_fnum;
1051 linenr_T *lp;
1052 win_T *win;
Bram Moolenaarbd1e5d22009-04-29 09:02:44 +00001053 tabpage_T *tab;
Bram Moolenaarb6a76ff2013-02-06 12:33:21 +01001054 static pos_T initpos = INIT_POS_T(1, 0, 0);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055
1056 if (line2 < line1 && amount_after == 0L) /* nothing to do */
1057 return;
1058
1059 if (!cmdmod.lockmarks)
1060 {
1061 /* named marks, lower case and upper case */
1062 for (i = 0; i < NMARKS; i++)
1063 {
1064 one_adjust(&(curbuf->b_namedm[i].lnum));
1065 if (namedfm[i].fmark.fnum == fnum)
1066 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
1067 }
1068 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
1069 {
1070 if (namedfm[i].fmark.fnum == fnum)
1071 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
1072 }
1073
1074 /* last Insert position */
1075 one_adjust(&(curbuf->b_last_insert.lnum));
1076
1077 /* last change position */
1078 one_adjust(&(curbuf->b_last_change.lnum));
1079
Bram Moolenaarb6a76ff2013-02-06 12:33:21 +01001080 /* last cursor position, if it was set */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01001081 if (!EQUAL_POS(curbuf->b_last_cursor, initpos))
Bram Moolenaarb6a76ff2013-02-06 12:33:21 +01001082 one_adjust(&(curbuf->b_last_cursor.lnum));
1083
1084
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085#ifdef FEAT_JUMPLIST
1086 /* list of change positions */
1087 for (i = 0; i < curbuf->b_changelistlen; ++i)
1088 one_adjust_nodel(&(curbuf->b_changelist[i].lnum));
1089#endif
1090
Bram Moolenaar071d4272004-06-13 20:20:40 +00001091 /* Visual area */
Bram Moolenaara226a6d2006-02-26 23:59:20 +00001092 one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
1093 one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094
1095#ifdef FEAT_QUICKFIX
1096 /* quickfix marks */
Bram Moolenaar28c258f2006-01-25 22:02:51 +00001097 qf_mark_adjust(NULL, line1, line2, amount, amount_after);
1098 /* location lists */
Bram Moolenaarbd1e5d22009-04-29 09:02:44 +00001099 FOR_ALL_TAB_WINDOWS(tab, win)
Bram Moolenaar28c258f2006-01-25 22:02:51 +00001100 qf_mark_adjust(win, line1, line2, amount, amount_after);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001101#endif
1102
1103#ifdef FEAT_SIGNS
1104 sign_mark_adjust(line1, line2, amount, amount_after);
1105#endif
1106 }
1107
1108 /* previous context mark */
1109 one_adjust(&(curwin->w_pcmark.lnum));
1110
1111 /* previous pcmark */
1112 one_adjust(&(curwin->w_prev_pcmark.lnum));
1113
1114 /* saved cursor for formatting */
1115 if (saved_cursor.lnum != 0)
1116 one_adjust_nodel(&(saved_cursor.lnum));
1117
1118 /*
1119 * Adjust items in all windows related to the current buffer.
1120 */
Bram Moolenaarbd1e5d22009-04-29 09:02:44 +00001121 FOR_ALL_TAB_WINDOWS(tab, win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 {
1123#ifdef FEAT_JUMPLIST
1124 if (!cmdmod.lockmarks)
1125 /* Marks in the jumplist. When deleting lines, this may create
1126 * duplicate marks in the jumplist, they will be removed later. */
1127 for (i = 0; i < win->w_jumplistlen; ++i)
1128 if (win->w_jumplist[i].fmark.fnum == fnum)
1129 one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum));
1130#endif
1131
1132 if (win->w_buffer == curbuf)
1133 {
1134 if (!cmdmod.lockmarks)
1135 /* marks in the tag stack */
1136 for (i = 0; i < win->w_tagstacklen; i++)
1137 if (win->w_tagstack[i].fmark.fnum == fnum)
1138 one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum));
1139
Bram Moolenaar071d4272004-06-13 20:20:40 +00001140 /* the displayed Visual area */
1141 if (win->w_old_cursor_lnum != 0)
1142 {
1143 one_adjust_nodel(&(win->w_old_cursor_lnum));
1144 one_adjust_nodel(&(win->w_old_visual_lnum));
1145 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001146
1147 /* topline and cursor position for windows with the same buffer
1148 * other than the current window */
1149 if (win != curwin)
1150 {
1151 if (win->w_topline >= line1 && win->w_topline <= line2)
1152 {
1153 if (amount == MAXLNUM) /* topline is deleted */
1154 {
1155 if (line1 <= 1)
1156 win->w_topline = 1;
1157 else
1158 win->w_topline = line1 - 1;
1159 }
1160 else /* keep topline on the same line */
1161 win->w_topline += amount;
1162#ifdef FEAT_DIFF
1163 win->w_topfill = 0;
1164#endif
1165 }
1166 else if (amount_after && win->w_topline > line2)
1167 {
1168 win->w_topline += amount_after;
1169#ifdef FEAT_DIFF
1170 win->w_topfill = 0;
1171#endif
1172 }
1173 if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2)
1174 {
1175 if (amount == MAXLNUM) /* line with cursor is deleted */
1176 {
1177 if (line1 <= 1)
1178 win->w_cursor.lnum = 1;
1179 else
1180 win->w_cursor.lnum = line1 - 1;
1181 win->w_cursor.col = 0;
1182 }
1183 else /* keep cursor on the same line */
1184 win->w_cursor.lnum += amount;
1185 }
1186 else if (amount_after && win->w_cursor.lnum > line2)
1187 win->w_cursor.lnum += amount_after;
1188 }
1189
1190#ifdef FEAT_FOLDING
1191 /* adjust folds */
Bram Moolenaar88d298a2017-03-14 21:53:58 +01001192 if (adjust_folds)
1193 foldMarkAdjust(win, line1, line2, amount, amount_after);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001194#endif
1195 }
1196 }
1197
1198#ifdef FEAT_DIFF
1199 /* adjust diffs */
1200 diff_mark_adjust(line1, line2, amount, amount_after);
1201#endif
1202}
1203
1204/* This code is used often, needs to be fast. */
1205#define col_adjust(pp) \
1206 { \
1207 posp = pp; \
1208 if (posp->lnum == lnum && posp->col >= mincol) \
1209 { \
1210 posp->lnum += lnum_amount; \
1211 if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
1212 posp->col = 0; \
1213 else \
1214 posp->col += col_amount; \
1215 } \
1216 }
1217
1218/*
1219 * Adjust marks in line "lnum" at column "mincol" and further: add
1220 * "lnum_amount" to the line number and add "col_amount" to the column
1221 * position.
1222 */
1223 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001224mark_col_adjust(
1225 linenr_T lnum,
1226 colnr_T mincol,
1227 long lnum_amount,
1228 long col_amount)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001229{
1230 int i;
1231 int fnum = curbuf->b_fnum;
1232 win_T *win;
1233 pos_T *posp;
1234
1235 if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
1236 return; /* nothing to do */
1237
1238 /* named marks, lower case and upper case */
1239 for (i = 0; i < NMARKS; i++)
1240 {
1241 col_adjust(&(curbuf->b_namedm[i]));
1242 if (namedfm[i].fmark.fnum == fnum)
1243 col_adjust(&(namedfm[i].fmark.mark));
1244 }
1245 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
1246 {
1247 if (namedfm[i].fmark.fnum == fnum)
1248 col_adjust(&(namedfm[i].fmark.mark));
1249 }
1250
1251 /* last Insert position */
1252 col_adjust(&(curbuf->b_last_insert));
1253
1254 /* last change position */
1255 col_adjust(&(curbuf->b_last_change));
1256
1257#ifdef FEAT_JUMPLIST
1258 /* list of change positions */
1259 for (i = 0; i < curbuf->b_changelistlen; ++i)
1260 col_adjust(&(curbuf->b_changelist[i]));
1261#endif
1262
Bram Moolenaar071d4272004-06-13 20:20:40 +00001263 /* Visual area */
Bram Moolenaara226a6d2006-02-26 23:59:20 +00001264 col_adjust(&(curbuf->b_visual.vi_start));
1265 col_adjust(&(curbuf->b_visual.vi_end));
Bram Moolenaar071d4272004-06-13 20:20:40 +00001266
1267 /* previous context mark */
1268 col_adjust(&(curwin->w_pcmark));
1269
1270 /* previous pcmark */
1271 col_adjust(&(curwin->w_prev_pcmark));
1272
1273 /* saved cursor for formatting */
1274 col_adjust(&saved_cursor);
1275
1276 /*
1277 * Adjust items in all windows related to the current buffer.
1278 */
1279 FOR_ALL_WINDOWS(win)
1280 {
1281#ifdef FEAT_JUMPLIST
1282 /* marks in the jumplist */
1283 for (i = 0; i < win->w_jumplistlen; ++i)
1284 if (win->w_jumplist[i].fmark.fnum == fnum)
1285 col_adjust(&(win->w_jumplist[i].fmark.mark));
1286#endif
1287
1288 if (win->w_buffer == curbuf)
1289 {
1290 /* marks in the tag stack */
1291 for (i = 0; i < win->w_tagstacklen; i++)
1292 if (win->w_tagstack[i].fmark.fnum == fnum)
1293 col_adjust(&(win->w_tagstack[i].fmark.mark));
1294
1295 /* cursor position for other windows with the same buffer */
1296 if (win != curwin)
1297 col_adjust(&win->w_cursor);
1298 }
1299 }
1300}
1301
1302#ifdef FEAT_JUMPLIST
1303/*
1304 * When deleting lines, this may create duplicate marks in the
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001305 * jumplist. They will be removed here for the specified window.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306 */
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001307 void
1308cleanup_jumplist(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001309{
1310 int i;
1311 int from, to;
1312
1313 to = 0;
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001314 for (from = 0; from < wp->w_jumplistlen; ++from)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001315 {
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001316 if (wp->w_jumplistidx == from)
1317 wp->w_jumplistidx = to;
1318 for (i = from + 1; i < wp->w_jumplistlen; ++i)
1319 if (wp->w_jumplist[i].fmark.fnum
1320 == wp->w_jumplist[from].fmark.fnum
1321 && wp->w_jumplist[from].fmark.fnum != 0
1322 && wp->w_jumplist[i].fmark.mark.lnum
1323 == wp->w_jumplist[from].fmark.mark.lnum)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001324 break;
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001325 if (i >= wp->w_jumplistlen) /* no duplicate */
1326 wp->w_jumplist[to++] = wp->w_jumplist[from];
Bram Moolenaar071d4272004-06-13 20:20:40 +00001327 else
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001328 vim_free(wp->w_jumplist[from].fname);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329 }
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001330 if (wp->w_jumplistidx == wp->w_jumplistlen)
1331 wp->w_jumplistidx = to;
1332 wp->w_jumplistlen = to;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001333}
1334
Bram Moolenaar071d4272004-06-13 20:20:40 +00001335/*
1336 * Copy the jumplist from window "from" to window "to".
1337 */
1338 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001339copy_jumplist(win_T *from, win_T *to)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001340{
1341 int i;
1342
1343 for (i = 0; i < from->w_jumplistlen; ++i)
1344 {
1345 to->w_jumplist[i] = from->w_jumplist[i];
1346 if (from->w_jumplist[i].fname != NULL)
1347 to->w_jumplist[i].fname = vim_strsave(from->w_jumplist[i].fname);
1348 }
1349 to->w_jumplistlen = from->w_jumplistlen;
1350 to->w_jumplistidx = from->w_jumplistidx;
1351}
1352
1353/*
1354 * Free items in the jumplist of window "wp".
1355 */
1356 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001357free_jumplist(win_T *wp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001358{
1359 int i;
1360
1361 for (i = 0; i < wp->w_jumplistlen; ++i)
1362 vim_free(wp->w_jumplist[i].fname);
1363}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001364#endif /* FEAT_JUMPLIST */
1365
1366 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001367set_last_cursor(win_T *win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001368{
Bram Moolenaar9db12932013-11-03 00:20:52 +01001369 if (win->w_buffer != NULL)
1370 win->w_buffer->b_last_cursor = win->w_cursor;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001371}
1372
Bram Moolenaarea408852005-06-25 22:49:46 +00001373#if defined(EXITFREE) || defined(PROTO)
1374 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001375free_all_marks(void)
Bram Moolenaarea408852005-06-25 22:49:46 +00001376{
1377 int i;
1378
1379 for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
1380 if (namedfm[i].fmark.mark.lnum != 0)
1381 vim_free(namedfm[i].fname);
1382}
1383#endif
1384
Bram Moolenaar071d4272004-06-13 20:20:40 +00001385#if defined(FEAT_VIMINFO) || defined(PROTO)
1386 int
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001387read_viminfo_filemark(vir_T *virp, int force)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001388{
1389 char_u *str;
1390 xfmark_T *fm;
1391 int i;
1392
1393 /* We only get here if line[0] == '\'' or '-'.
1394 * Illegal mark names are ignored (for future expansion). */
1395 str = virp->vir_line + 1;
1396 if (
1397#ifndef EBCDIC
1398 *str <= 127 &&
1399#endif
1400 ((*virp->vir_line == '\'' && (VIM_ISDIGIT(*str) || isupper(*str)))
1401 || (*virp->vir_line == '-' && *str == '\'')))
1402 {
1403 if (*str == '\'')
1404 {
1405#ifdef FEAT_JUMPLIST
1406 /* If the jumplist isn't full insert fmark as oldest entry */
1407 if (curwin->w_jumplistlen == JUMPLISTSIZE)
1408 fm = NULL;
1409 else
1410 {
1411 for (i = curwin->w_jumplistlen; i > 0; --i)
1412 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1];
1413 ++curwin->w_jumplistidx;
1414 ++curwin->w_jumplistlen;
1415 fm = &curwin->w_jumplist[0];
1416 fm->fmark.mark.lnum = 0;
1417 fm->fname = NULL;
1418 }
1419#else
1420 fm = NULL;
1421#endif
1422 }
1423 else if (VIM_ISDIGIT(*str))
1424 fm = &namedfm[*str - '0' + NMARKS];
1425 else
1426 fm = &namedfm[*str - 'A'];
1427 if (fm != NULL && (fm->fmark.mark.lnum == 0 || force))
1428 {
1429 str = skipwhite(str + 1);
1430 fm->fmark.mark.lnum = getdigits(&str);
1431 str = skipwhite(str);
1432 fm->fmark.mark.col = getdigits(&str);
1433#ifdef FEAT_VIRTUALEDIT
1434 fm->fmark.mark.coladd = 0;
1435#endif
1436 fm->fmark.fnum = 0;
1437 str = skipwhite(str);
1438 vim_free(fm->fname);
1439 fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line),
1440 FALSE);
Bram Moolenaar2d358992016-06-12 21:20:54 +02001441 fm->time_set = 0;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001442 }
1443 }
1444 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd);
1445}
1446
Bram Moolenaar2d358992016-06-12 21:20:54 +02001447static xfmark_T *vi_namedfm = NULL;
1448#ifdef FEAT_JUMPLIST
1449static xfmark_T *vi_jumplist = NULL;
1450static int vi_jumplist_len = 0;
1451#endif
1452
1453/*
1454 * Prepare for reading viminfo marks when writing viminfo later.
1455 */
1456 void
1457prepare_viminfo_marks(void)
1458{
1459 vi_namedfm = (xfmark_T *)alloc_clear((NMARKS + EXTRA_MARKS)
1460 * (int)sizeof(xfmark_T));
1461#ifdef FEAT_JUMPLIST
1462 vi_jumplist = (xfmark_T *)alloc_clear(JUMPLISTSIZE
1463 * (int)sizeof(xfmark_T));
1464 vi_jumplist_len = 0;
1465#endif
1466}
1467
1468 void
1469finish_viminfo_marks(void)
1470{
1471 int i;
1472
1473 if (vi_namedfm != NULL)
1474 {
1475 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
1476 vim_free(vi_namedfm[i].fname);
Bram Moolenaard23a8232018-02-10 18:45:26 +01001477 VIM_CLEAR(vi_namedfm);
Bram Moolenaar2d358992016-06-12 21:20:54 +02001478 }
1479#ifdef FEAT_JUMPLIST
1480 if (vi_jumplist != NULL)
1481 {
1482 for (i = 0; i < vi_jumplist_len; ++i)
1483 vim_free(vi_jumplist[i].fname);
Bram Moolenaard23a8232018-02-10 18:45:26 +01001484 VIM_CLEAR(vi_jumplist);
Bram Moolenaar2d358992016-06-12 21:20:54 +02001485 }
1486#endif
1487}
1488
1489/*
1490 * Accept a new style mark line from the viminfo, store it when it's new.
1491 */
1492 void
1493handle_viminfo_mark(garray_T *values, int force)
1494{
1495 bval_T *vp = (bval_T *)values->ga_data;
1496 int name;
1497 linenr_T lnum;
1498 colnr_T col;
1499 time_t timestamp;
1500 xfmark_T *fm = NULL;
1501
1502 /* Check the format:
1503 * |{bartype},{name},{lnum},{col},{timestamp},{filename} */
1504 if (values->ga_len < 5
1505 || vp[0].bv_type != BVAL_NR
1506 || vp[1].bv_type != BVAL_NR
1507 || vp[2].bv_type != BVAL_NR
1508 || vp[3].bv_type != BVAL_NR
1509 || vp[4].bv_type != BVAL_STRING)
1510 return;
1511
1512 name = vp[0].bv_nr;
1513 if (name != '\'' && !VIM_ISDIGIT(name) && !ASCII_ISUPPER(name))
1514 return;
1515 lnum = vp[1].bv_nr;
1516 col = vp[2].bv_nr;
1517 if (lnum <= 0 || col < 0)
1518 return;
1519 timestamp = (time_t)vp[3].bv_nr;
1520
1521 if (name == '\'')
1522 {
1523#ifdef FEAT_JUMPLIST
1524 if (vi_jumplist != NULL)
1525 {
1526 if (vi_jumplist_len < JUMPLISTSIZE)
1527 fm = &vi_jumplist[vi_jumplist_len++];
1528 }
1529 else
1530 {
1531 int idx;
1532 int i;
1533
1534 /* If we have a timestamp insert it in the right place. */
1535 if (timestamp != 0)
1536 {
1537 for (idx = curwin->w_jumplistlen - 1; idx >= 0; --idx)
1538 if (curwin->w_jumplist[idx].time_set < timestamp)
Bram Moolenaarece74ab2016-06-13 22:22:15 +02001539 {
1540 ++idx;
Bram Moolenaar2d358992016-06-12 21:20:54 +02001541 break;
Bram Moolenaarece74ab2016-06-13 22:22:15 +02001542 }
Bram Moolenaar678e4802016-06-17 22:38:46 +02001543 /* idx cannot be zero now */
Bram Moolenaarece74ab2016-06-13 22:22:15 +02001544 if (idx < 0 && curwin->w_jumplistlen < JUMPLISTSIZE)
1545 /* insert as the oldest entry */
1546 idx = 0;
Bram Moolenaar2d358992016-06-12 21:20:54 +02001547 }
1548 else if (curwin->w_jumplistlen < JUMPLISTSIZE)
1549 /* insert as oldest entry */
1550 idx = 0;
1551 else
1552 idx = -1;
1553
1554 if (idx >= 0)
1555 {
1556 if (curwin->w_jumplistlen == JUMPLISTSIZE)
1557 {
1558 /* Drop the oldest entry. */
Bram Moolenaar28607ba2016-06-15 21:44:51 +02001559 --idx;
Bram Moolenaar2d358992016-06-12 21:20:54 +02001560 vim_free(curwin->w_jumplist[0].fname);
1561 for (i = 0; i < idx; ++i)
1562 curwin->w_jumplist[i] = curwin->w_jumplist[i + 1];
1563 }
1564 else
1565 {
1566 /* Move newer entries forward. */
Bram Moolenaar2d358992016-06-12 21:20:54 +02001567 for (i = curwin->w_jumplistlen; i > idx; --i)
1568 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1];
1569 ++curwin->w_jumplistidx;
1570 ++curwin->w_jumplistlen;
1571 }
1572 fm = &curwin->w_jumplist[idx];
1573 fm->fmark.mark.lnum = 0;
1574 fm->fname = NULL;
1575 fm->time_set = 0;
1576 }
1577 }
1578#endif
1579 }
1580 else
1581 {
1582 int idx;
1583
1584 if (VIM_ISDIGIT(name))
1585 {
1586 if (vi_namedfm != NULL)
1587 idx = name - '0' + NMARKS;
1588 else
1589 {
1590 int i;
1591
1592 /* Do not use the name from the viminfo file, insert in time
1593 * order. */
1594 for (idx = NMARKS; idx < NMARKS + EXTRA_MARKS; ++idx)
1595 if (namedfm[idx].time_set < timestamp)
1596 break;
1597 if (idx == NMARKS + EXTRA_MARKS)
1598 /* All existing entries are newer. */
1599 return;
1600 i = NMARKS + EXTRA_MARKS - 1;
1601
1602 vim_free(namedfm[i].fname);
1603 for ( ; i > idx; --i)
1604 namedfm[i] = namedfm[i - 1];
1605 namedfm[idx].fname = NULL;
1606 }
1607 }
1608 else
1609 idx = name - 'A';
1610 if (vi_namedfm != NULL)
1611 fm = &vi_namedfm[idx];
1612 else
1613 fm = &namedfm[idx];
1614 }
1615
1616 if (fm != NULL)
1617 {
Bram Moolenaar156919f2016-10-15 20:46:20 +02001618 if (vi_namedfm != NULL || fm->fmark.mark.lnum == 0
1619 || fm->time_set < timestamp || force)
Bram Moolenaar2d358992016-06-12 21:20:54 +02001620 {
1621 fm->fmark.mark.lnum = lnum;
1622 fm->fmark.mark.col = col;
1623#ifdef FEAT_VIRTUALEDIT
1624 fm->fmark.mark.coladd = 0;
1625#endif
1626 fm->fmark.fnum = 0;
1627 vim_free(fm->fname);
1628 if (vp[4].bv_allocated)
1629 {
1630 fm->fname = vp[4].bv_string;
1631 vp[4].bv_string = NULL;
1632 }
1633 else
1634 fm->fname = vim_strsave(vp[4].bv_string);
1635 fm->time_set = timestamp;
1636 }
1637 }
1638}
1639
Bram Moolenaare6278052017-08-13 18:11:17 +02001640/*
1641 * Return TRUE if marks for "buf" should not be written.
1642 */
1643 static int
1644skip_for_viminfo(buf_T *buf)
1645{
1646 return
1647#ifdef FEAT_TERMINAL
1648 bt_terminal(buf) ||
1649#endif
1650 removable(buf->b_ffname);
1651}
1652
Bram Moolenaar071d4272004-06-13 20:20:40 +00001653 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001654write_viminfo_filemarks(FILE *fp)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001655{
1656 int i;
1657 char_u *name;
1658 buf_T *buf;
1659 xfmark_T *fm;
Bram Moolenaar2d358992016-06-12 21:20:54 +02001660 int vi_idx;
1661 int idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001662
1663 if (get_viminfo_parameter('f') == 0)
1664 return;
1665
Bram Moolenaar2f1e0502010-08-13 11:18:02 +02001666 fputs(_("\n# File marks:\n"), fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001667
Bram Moolenaar2d358992016-06-12 21:20:54 +02001668 /* Write the filemarks 'A - 'Z */
1669 for (i = 0; i < NMARKS; i++)
1670 {
1671 if (vi_namedfm != NULL && (vi_namedfm[i].time_set > namedfm[i].time_set
1672 || namedfm[i].fmark.mark.lnum == 0))
1673 fm = &vi_namedfm[i];
1674 else
1675 fm = &namedfm[i];
1676 write_one_filemark(fp, fm, '\'', i + 'A');
1677 }
1678
Bram Moolenaar071d4272004-06-13 20:20:40 +00001679 /*
1680 * Find a mark that is the same file and position as the cursor.
1681 * That one, or else the last one is deleted.
1682 * Move '0 to '1, '1 to '2, etc. until the matching one or '9
Bram Moolenaar2d358992016-06-12 21:20:54 +02001683 * Set the '0 mark to current cursor position.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001684 */
Bram Moolenaare6278052017-08-13 18:11:17 +02001685 if (curbuf->b_ffname != NULL && !skip_for_viminfo(curbuf))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001686 {
1687 name = buflist_nr2name(curbuf->b_fnum, TRUE, FALSE);
1688 for (i = NMARKS; i < NMARKS + EXTRA_MARKS - 1; ++i)
1689 if (namedfm[i].fmark.mark.lnum == curwin->w_cursor.lnum
1690 && (namedfm[i].fname == NULL
1691 ? namedfm[i].fmark.fnum == curbuf->b_fnum
1692 : (name != NULL
1693 && STRCMP(name, namedfm[i].fname) == 0)))
1694 break;
1695 vim_free(name);
1696
1697 vim_free(namedfm[i].fname);
1698 for ( ; i > NMARKS; --i)
1699 namedfm[i] = namedfm[i - 1];
1700 namedfm[NMARKS].fmark.mark = curwin->w_cursor;
1701 namedfm[NMARKS].fmark.fnum = curbuf->b_fnum;
1702 namedfm[NMARKS].fname = NULL;
Bram Moolenaar2d358992016-06-12 21:20:54 +02001703 namedfm[NMARKS].time_set = vim_time();
Bram Moolenaar071d4272004-06-13 20:20:40 +00001704 }
1705
Bram Moolenaar2d358992016-06-12 21:20:54 +02001706 /* Write the filemarks '0 - '9. Newest (highest timestamp) first. */
1707 vi_idx = NMARKS;
1708 idx = NMARKS;
1709 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
1710 {
Bram Moolenaar36f0f062016-06-14 23:02:46 +02001711 xfmark_T *vi_fm = vi_namedfm != NULL ? &vi_namedfm[vi_idx] : NULL;
1712
1713 if (vi_fm != NULL
1714 && vi_fm->fmark.mark.lnum != 0
1715 && (vi_fm->time_set > namedfm[idx].time_set
Bram Moolenaar2d358992016-06-12 21:20:54 +02001716 || namedfm[idx].fmark.mark.lnum == 0))
Bram Moolenaar36f0f062016-06-14 23:02:46 +02001717 {
1718 fm = vi_fm;
1719 ++vi_idx;
1720 }
Bram Moolenaar2d358992016-06-12 21:20:54 +02001721 else
Bram Moolenaar36f0f062016-06-14 23:02:46 +02001722 {
Bram Moolenaar2d358992016-06-12 21:20:54 +02001723 fm = &namedfm[idx++];
Bram Moolenaar36f0f062016-06-14 23:02:46 +02001724 if (vi_fm != NULL
1725 && vi_fm->fmark.mark.lnum == fm->fmark.mark.lnum
1726 && vi_fm->time_set == fm->time_set
1727 && ((vi_fm->fmark.fnum != 0
1728 && vi_fm->fmark.fnum == fm->fmark.fnum)
1729 || (vi_fm->fname != NULL
1730 && fm->fname != NULL
1731 && STRCMP(vi_fm->fname, fm->fname) == 0)))
1732 ++vi_idx; /* skip duplicate */
1733 }
Bram Moolenaar2d358992016-06-12 21:20:54 +02001734 write_one_filemark(fp, fm, '\'', i - NMARKS + '0');
1735 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001736
1737#ifdef FEAT_JUMPLIST
1738 /* Write the jumplist with -' */
Bram Moolenaar2f1e0502010-08-13 11:18:02 +02001739 fputs(_("\n# Jumplist (newest first):\n"), fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001740 setpcmark(); /* add current cursor position */
Bram Moolenaara7e18d22018-02-11 14:29:49 +01001741 cleanup_jumplist(curwin);
Bram Moolenaarece74ab2016-06-13 22:22:15 +02001742 vi_idx = 0;
1743 idx = curwin->w_jumplistlen - 1;
1744 for (i = 0; i < JUMPLISTSIZE; ++i)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001745 {
Bram Moolenaarece74ab2016-06-13 22:22:15 +02001746 xfmark_T *vi_fm;
1747
1748 fm = idx >= 0 ? &curwin->w_jumplist[idx] : NULL;
1749 vi_fm = vi_idx < vi_jumplist_len ? &vi_jumplist[vi_idx] : NULL;
1750 if (fm == NULL && vi_fm == NULL)
1751 break;
1752 if (fm == NULL || (vi_fm != NULL && fm->time_set < vi_fm->time_set))
1753 {
1754 fm = vi_fm;
1755 ++vi_idx;
1756 }
1757 else
1758 --idx;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001759 if (fm->fmark.fnum == 0
1760 || ((buf = buflist_findnr(fm->fmark.fnum)) != NULL
Bram Moolenaare6278052017-08-13 18:11:17 +02001761 && !skip_for_viminfo(buf)))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001762 write_one_filemark(fp, fm, '-', '\'');
1763 }
1764#endif
1765}
1766
1767 static void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001768write_one_filemark(
1769 FILE *fp,
1770 xfmark_T *fm,
1771 int c1,
1772 int c2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001773{
1774 char_u *name;
1775
1776 if (fm->fmark.mark.lnum == 0) /* not set */
1777 return;
1778
1779 if (fm->fmark.fnum != 0) /* there is a buffer */
1780 name = buflist_nr2name(fm->fmark.fnum, TRUE, FALSE);
1781 else
1782 name = fm->fname; /* use name from .viminfo */
1783 if (name != NULL && *name != NUL)
1784 {
1785 fprintf(fp, "%c%c %ld %ld ", c1, c2, (long)fm->fmark.mark.lnum,
1786 (long)fm->fmark.mark.col);
1787 viminfo_writestring(fp, name);
Bram Moolenaar2d358992016-06-12 21:20:54 +02001788
1789 /* Barline: |{bartype},{name},{lnum},{col},{timestamp},{filename}
1790 * size up to filename: 8 + 3 * 20 */
1791 fprintf(fp, "|%d,%d,%ld,%ld,%ld,", BARTYPE_MARK, c2,
1792 (long)fm->fmark.mark.lnum, (long)fm->fmark.mark.col,
1793 (long)fm->time_set);
1794 barline_writestring(fp, name, LSIZE - 70);
1795 putc('\n', fp);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001796 }
1797
1798 if (fm->fmark.fnum != 0)
1799 vim_free(name);
1800}
1801
1802/*
1803 * Return TRUE if "name" is on removable media (depending on 'viminfo').
1804 */
1805 int
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001806removable(char_u *name)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001807{
1808 char_u *p;
1809 char_u part[51];
1810 int retval = FALSE;
Bram Moolenaarcfc6c432005-06-06 21:50:35 +00001811 size_t n;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001812
1813 name = home_replace_save(NULL, name);
1814 if (name != NULL)
1815 {
1816 for (p = p_viminfo; *p; )
1817 {
1818 copy_option_part(&p, part, 51, ", ");
Bram Moolenaarcfc6c432005-06-06 21:50:35 +00001819 if (part[0] == 'r')
Bram Moolenaar071d4272004-06-13 20:20:40 +00001820 {
Bram Moolenaarcfc6c432005-06-06 21:50:35 +00001821 n = STRLEN(part + 1);
1822 if (MB_STRNICMP(part + 1, name, n) == 0)
1823 {
1824 retval = TRUE;
1825 break;
1826 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001827 }
1828 }
1829 vim_free(name);
1830 }
1831 return retval;
1832}
1833
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001834 static void
1835write_one_mark(FILE *fp_out, int c, pos_T *pos)
1836{
1837 if (pos->lnum != 0)
1838 fprintf(fp_out, "\t%c\t%ld\t%d\n", c, (long)pos->lnum, (int)pos->col);
1839}
1840
1841
1842 static void
1843write_buffer_marks(buf_T *buf, FILE *fp_out)
1844{
1845 int i;
1846 pos_T pos;
1847
1848 home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE);
1849 fprintf(fp_out, "\n> ");
1850 viminfo_writestring(fp_out, IObuff);
1851
1852 /* Write the last used timestamp as the lnum of the non-existing mark '*'.
1853 * Older Vims will ignore it and/or copy it. */
1854 pos.lnum = (linenr_T)buf->b_last_used;
1855 pos.col = 0;
1856 write_one_mark(fp_out, '*', &pos);
1857
1858 write_one_mark(fp_out, '"', &buf->b_last_cursor);
1859 write_one_mark(fp_out, '^', &buf->b_last_insert);
1860 write_one_mark(fp_out, '.', &buf->b_last_change);
1861#ifdef FEAT_JUMPLIST
1862 /* changelist positions are stored oldest first */
1863 for (i = 0; i < buf->b_changelistlen; ++i)
1864 {
1865 /* skip duplicates */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +01001866 if (i == 0 || !EQUAL_POS(buf->b_changelist[i - 1],
1867 buf->b_changelist[i]))
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001868 write_one_mark(fp_out, '+', &buf->b_changelist[i]);
1869 }
1870#endif
1871 for (i = 0; i < NMARKS; i++)
1872 write_one_mark(fp_out, 'a' + i, &buf->b_namedm[i]);
1873}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001874
1875/*
1876 * Write all the named marks for all buffers.
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001877 * When "buflist" is not NULL fill it with the buffers for which marks are to
1878 * be written.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001879 */
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001880 void
1881write_viminfo_marks(FILE *fp_out, garray_T *buflist)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001882{
Bram Moolenaar071d4272004-06-13 20:20:40 +00001883 buf_T *buf;
1884 int is_mark_set;
1885 int i;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001886 win_T *win;
Bram Moolenaarf740b292006-02-16 22:11:02 +00001887 tabpage_T *tp;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001888
1889 /*
1890 * Set b_last_cursor for the all buffers that have a window.
1891 */
Bram Moolenaarf740b292006-02-16 22:11:02 +00001892 FOR_ALL_TAB_WINDOWS(tp, win)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001893 set_last_cursor(win);
Bram Moolenaar071d4272004-06-13 20:20:40 +00001894
Bram Moolenaar2f1e0502010-08-13 11:18:02 +02001895 fputs(_("\n# History of marks within files (newest to oldest):\n"), fp_out);
Bram Moolenaar29323592016-07-24 22:04:11 +02001896 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001897 {
1898 /*
1899 * Only write something if buffer has been loaded and at least one
1900 * mark is set.
1901 */
1902 if (buf->b_marks_read)
1903 {
1904 if (buf->b_last_cursor.lnum != 0)
1905 is_mark_set = TRUE;
1906 else
1907 {
1908 is_mark_set = FALSE;
1909 for (i = 0; i < NMARKS; i++)
1910 if (buf->b_namedm[i].lnum != 0)
1911 {
1912 is_mark_set = TRUE;
1913 break;
1914 }
1915 }
1916 if (is_mark_set && buf->b_ffname != NULL
Bram Moolenaare6278052017-08-13 18:11:17 +02001917 && buf->b_ffname[0] != NUL
1918 && !skip_for_viminfo(buf))
Bram Moolenaar071d4272004-06-13 20:20:40 +00001919 {
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001920 if (buflist == NULL)
1921 write_buffer_marks(buf, fp_out);
1922 else if (ga_grow(buflist, 1) == OK)
1923 ((buf_T **)buflist->ga_data)[buflist->ga_len++] = buf;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001924 }
1925 }
1926 }
Bram Moolenaar071d4272004-06-13 20:20:40 +00001927}
1928
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001929/*
1930 * Compare functions for qsort() below, that compares b_last_used.
1931 */
1932 static int
1933#ifdef __BORLANDC__
1934_RTLENTRYF
1935#endif
1936buf_compare(const void *s1, const void *s2)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001937{
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001938 buf_T *buf1 = *(buf_T **)s1;
1939 buf_T *buf2 = *(buf_T **)s2;
1940
1941 if (buf1->b_last_used == buf2->b_last_used)
1942 return 0;
1943 return buf1->b_last_used > buf2->b_last_used ? -1 : 1;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001944}
1945
1946/*
1947 * Handle marks in the viminfo file:
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001948 * fp_out != NULL: copy marks, in time order with buffers in "buflist".
Bram Moolenaard812df62008-11-09 12:46:09 +00001949 * fp_out == NULL && (flags & VIF_WANT_MARKS): read marks for curbuf only
1950 * fp_out == NULL && (flags & VIF_GET_OLDFILES | VIF_FORCEIT): fill v:oldfiles
Bram Moolenaar071d4272004-06-13 20:20:40 +00001951 */
1952 void
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001953copy_viminfo_marks(
1954 vir_T *virp,
1955 FILE *fp_out,
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001956 garray_T *buflist,
Bram Moolenaar52ea13d2016-01-30 18:51:09 +01001957 int eof,
1958 int flags)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001959{
1960 char_u *line = virp->vir_line;
1961 buf_T *buf;
1962 int num_marked_files;
1963 int load_marks;
1964 int copy_marks_out;
1965 char_u *str;
1966 int i;
1967 char_u *p;
1968 char_u *name_buf;
1969 pos_T pos;
Bram Moolenaard812df62008-11-09 12:46:09 +00001970#ifdef FEAT_EVAL
1971 list_T *list = NULL;
1972#endif
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001973 int count = 0;
1974 int buflist_used = 0;
1975 buf_T *buflist_buf = NULL;
Bram Moolenaar071d4272004-06-13 20:20:40 +00001976
1977 if ((name_buf = alloc(LSIZE)) == NULL)
1978 return;
1979 *name_buf = NUL;
Bram Moolenaard812df62008-11-09 12:46:09 +00001980
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02001981 if (fp_out != NULL && buflist->ga_len > 0)
1982 {
1983 /* Sort the list of buffers on b_last_used. */
1984 qsort(buflist->ga_data, (size_t)buflist->ga_len,
1985 sizeof(buf_T *), buf_compare);
1986 buflist_buf = ((buf_T **)buflist->ga_data)[0];
1987 }
1988
Bram Moolenaard812df62008-11-09 12:46:09 +00001989#ifdef FEAT_EVAL
1990 if (fp_out == NULL && (flags & (VIF_GET_OLDFILES | VIF_FORCEIT)))
1991 {
1992 list = list_alloc();
1993 if (list != NULL)
1994 set_vim_var_list(VV_OLDFILES, list);
1995 }
1996#endif
1997
Bram Moolenaar071d4272004-06-13 20:20:40 +00001998 num_marked_files = get_viminfo_parameter('\'');
1999 while (!eof && (count < num_marked_files || fp_out == NULL))
2000 {
2001 if (line[0] != '>')
2002 {
2003 if (line[0] != '\n' && line[0] != '\r' && line[0] != '#')
2004 {
2005 if (viminfo_error("E576: ", _("Missing '>'"), line))
2006 break; /* too many errors, return now */
2007 }
2008 eof = vim_fgets(line, LSIZE, virp->vir_fd);
2009 continue; /* Skip this dud line */
2010 }
2011
2012 /*
2013 * Handle long line and translate escaped characters.
2014 * Find file name, set str to start.
2015 * Ignore leading and trailing white space.
2016 */
2017 str = skipwhite(line + 1);
2018 str = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE);
2019 if (str == NULL)
2020 continue;
2021 p = str + STRLEN(str);
2022 while (p != str && (*p == NUL || vim_isspace(*p)))
2023 p--;
2024 if (*p)
2025 p++;
2026 *p = NUL;
2027
Bram Moolenaard812df62008-11-09 12:46:09 +00002028#ifdef FEAT_EVAL
2029 if (list != NULL)
2030 list_append_string(list, str, -1);
2031#endif
2032
Bram Moolenaar071d4272004-06-13 20:20:40 +00002033 /*
2034 * If fp_out == NULL, load marks for current buffer.
2035 * If fp_out != NULL, copy marks for buffers not in buflist.
2036 */
2037 load_marks = copy_marks_out = FALSE;
2038 if (fp_out == NULL)
2039 {
Bram Moolenaard812df62008-11-09 12:46:09 +00002040 if ((flags & VIF_WANT_MARKS) && curbuf->b_ffname != NULL)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002041 {
2042 if (*name_buf == NUL) /* only need to do this once */
2043 home_replace(NULL, curbuf->b_ffname, name_buf, LSIZE, TRUE);
2044 if (fnamecmp(str, name_buf) == 0)
2045 load_marks = TRUE;
2046 }
2047 }
2048 else /* fp_out != NULL */
2049 {
2050 /* This is slow if there are many buffers!! */
Bram Moolenaar29323592016-07-24 22:04:11 +02002051 FOR_ALL_BUFFERS(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +00002052 if (buf->b_ffname != NULL)
2053 {
2054 home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
2055 if (fnamecmp(str, name_buf) == 0)
2056 break;
2057 }
2058
2059 /*
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002060 * Copy marks if the buffer has not been loaded.
Bram Moolenaar071d4272004-06-13 20:20:40 +00002061 */
2062 if (buf == NULL || !buf->b_marks_read)
2063 {
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002064 int did_read_line = FALSE;
2065
2066 if (buflist_buf != NULL)
2067 {
2068 /* Read the next line. If it has the "*" mark compare the
2069 * time stamps. Write entries from "buflist" that are
2070 * newer. */
2071 if (!(eof = viminfo_readline(virp)) && line[0] == TAB)
2072 {
2073 did_read_line = TRUE;
2074 if (line[1] == '*')
2075 {
2076 long ltime;
2077
2078 sscanf((char *)line + 2, "%ld ", &ltime);
2079 while ((time_T)ltime < buflist_buf->b_last_used)
2080 {
2081 write_buffer_marks(buflist_buf, fp_out);
2082 if (++count >= num_marked_files)
2083 break;
2084 if (++buflist_used == buflist->ga_len)
2085 {
2086 buflist_buf = NULL;
2087 break;
2088 }
2089 buflist_buf =
2090 ((buf_T **)buflist->ga_data)[buflist_used];
2091 }
2092 }
2093 else
2094 {
2095 /* No timestamp, must be written by an older Vim.
2096 * Assume all remaining buffers are older then
2097 * ours. */
2098 while (count < num_marked_files
2099 && buflist_used < buflist->ga_len)
2100 {
2101 buflist_buf = ((buf_T **)buflist->ga_data)
2102 [buflist_used++];
2103 write_buffer_marks(buflist_buf, fp_out);
2104 ++count;
2105 }
2106 buflist_buf = NULL;
2107 }
2108
2109 if (count >= num_marked_files)
2110 {
2111 vim_free(str);
2112 break;
2113 }
2114 }
2115 }
2116
Bram Moolenaar071d4272004-06-13 20:20:40 +00002117 fputs("\n> ", fp_out);
2118 viminfo_writestring(fp_out, str);
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002119 if (did_read_line)
2120 fputs((char *)line, fp_out);
2121
Bram Moolenaar071d4272004-06-13 20:20:40 +00002122 count++;
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002123 copy_marks_out = TRUE;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002124 }
2125 }
2126 vim_free(str);
2127
2128#ifdef FEAT_VIRTUALEDIT
2129 pos.coladd = 0;
2130#endif
2131 while (!(eof = viminfo_readline(virp)) && line[0] == TAB)
2132 {
2133 if (load_marks)
2134 {
2135 if (line[1] != NUL)
2136 {
Bram Moolenaare698add2011-02-25 15:11:22 +01002137 unsigned u;
2138
2139 sscanf((char *)line + 2, "%ld %u", &pos.lnum, &u);
2140 pos.col = u;
Bram Moolenaar071d4272004-06-13 20:20:40 +00002141 switch (line[1])
2142 {
2143 case '"': curbuf->b_last_cursor = pos; break;
2144 case '^': curbuf->b_last_insert = pos; break;
2145 case '.': curbuf->b_last_change = pos; break;
2146 case '+':
2147#ifdef FEAT_JUMPLIST
2148 /* changelist positions are stored oldest
2149 * first */
2150 if (curbuf->b_changelistlen == JUMPLISTSIZE)
2151 /* list is full, remove oldest entry */
2152 mch_memmove(curbuf->b_changelist,
2153 curbuf->b_changelist + 1,
2154 sizeof(pos_T) * (JUMPLISTSIZE - 1));
2155 else
2156 ++curbuf->b_changelistlen;
2157 curbuf->b_changelist[
2158 curbuf->b_changelistlen - 1] = pos;
2159#endif
2160 break;
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002161
2162 /* Using the line number for the last-used
2163 * timestamp. */
2164 case '*': curbuf->b_last_used = pos.lnum; break;
2165
Bram Moolenaar071d4272004-06-13 20:20:40 +00002166 default: if ((i = line[1] - 'a') >= 0 && i < NMARKS)
2167 curbuf->b_namedm[i] = pos;
2168 }
2169 }
2170 }
2171 else if (copy_marks_out)
2172 fputs((char *)line, fp_out);
2173 }
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002174
Bram Moolenaar071d4272004-06-13 20:20:40 +00002175 if (load_marks)
2176 {
2177#ifdef FEAT_JUMPLIST
2178 win_T *wp;
2179
2180 FOR_ALL_WINDOWS(wp)
2181 {
2182 if (wp->w_buffer == curbuf)
2183 wp->w_changelistidx = curbuf->b_changelistlen;
2184 }
2185#endif
2186 break;
2187 }
2188 }
Bram Moolenaarab9c89b2016-07-03 17:47:26 +02002189
2190 if (fp_out != NULL)
2191 /* Write any remaining entries from buflist. */
2192 while (count < num_marked_files && buflist_used < buflist->ga_len)
2193 {
2194 buflist_buf = ((buf_T **)buflist->ga_data)[buflist_used++];
2195 write_buffer_marks(buflist_buf, fp_out);
2196 ++count;
2197 }
2198
Bram Moolenaar071d4272004-06-13 20:20:40 +00002199 vim_free(name_buf);
2200}
2201#endif /* FEAT_VIMINFO */