7
|
1 /* vi:set ts=8 sts=4 sw=4:
|
|
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 * 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 */
|
|
28 static xfmark_T namedfm[NMARKS + EXTRA_MARKS]; /* marks with file nr */
|
|
29
|
|
30 static void fname2fnum __ARGS((xfmark_T *fm));
|
|
31 static void fmarks_check_one __ARGS((xfmark_T *fm, char_u *name, buf_T *buf));
|
|
32 static char_u *mark_line __ARGS((pos_T *mp, int lead_len));
|
|
33 static void show_one_mark __ARGS((int, char_u *, pos_T *, char_u *, int current));
|
|
34 #ifdef FEAT_JUMPLIST
|
|
35 static void cleanup_jumplist __ARGS((void));
|
|
36 #endif
|
|
37 #ifdef FEAT_VIMINFO
|
|
38 static void write_one_filemark __ARGS((FILE *fp, xfmark_T *fm, int c1, int c2));
|
|
39 #endif
|
|
40
|
|
41 /*
|
706
|
42 * Set named mark "c" at current cursor position.
|
7
|
43 * Returns OK on success, FAIL if bad name given.
|
|
44 */
|
|
45 int
|
|
46 setmark(c)
|
|
47 int c;
|
|
48 {
|
706
|
49 return setmark_pos(c, &curwin->w_cursor, curbuf->b_fnum);
|
|
50 }
|
|
51
|
|
52 /*
|
|
53 * Set named mark "c" to position "pos".
|
|
54 * When "c" is upper case use file "fnum".
|
|
55 * Returns OK on success, FAIL if bad name given.
|
|
56 */
|
|
57 int
|
|
58 setmark_pos(c, pos, fnum)
|
|
59 int c;
|
|
60 pos_T *pos;
|
|
61 int fnum;
|
|
62 {
|
7
|
63 int i;
|
|
64
|
|
65 /* Check for a special key (may cause islower() to crash). */
|
|
66 if (c < 0)
|
|
67 return FAIL;
|
|
68
|
|
69 if (c == '\'' || c == '`')
|
|
70 {
|
706
|
71 if (pos == &curwin->w_cursor)
|
|
72 {
|
|
73 setpcmark();
|
|
74 /* keep it even when the cursor doesn't move */
|
|
75 curwin->w_prev_pcmark = curwin->w_pcmark;
|
|
76 }
|
|
77 else
|
|
78 curwin->w_pcmark = *pos;
|
7
|
79 return OK;
|
|
80 }
|
|
81
|
1533
|
82 if (c == '"')
|
|
83 {
|
|
84 curbuf->b_last_cursor = *pos;
|
|
85 return OK;
|
|
86 }
|
|
87
|
7
|
88 /* Allow setting '[ and '] for an autocommand that simulates reading a
|
|
89 * file. */
|
|
90 if (c == '[')
|
|
91 {
|
706
|
92 curbuf->b_op_start = *pos;
|
7
|
93 return OK;
|
|
94 }
|
|
95 if (c == ']')
|
|
96 {
|
706
|
97 curbuf->b_op_end = *pos;
|
7
|
98 return OK;
|
|
99 }
|
|
100
|
|
101 #ifndef EBCDIC
|
|
102 if (c > 'z') /* some islower() and isupper() cannot handle
|
|
103 characters above 127 */
|
|
104 return FAIL;
|
|
105 #endif
|
|
106 if (islower(c))
|
|
107 {
|
|
108 i = c - 'a';
|
706
|
109 curbuf->b_namedm[i] = *pos;
|
7
|
110 return OK;
|
|
111 }
|
|
112 if (isupper(c))
|
|
113 {
|
|
114 i = c - 'A';
|
706
|
115 namedfm[i].fmark.mark = *pos;
|
|
116 namedfm[i].fmark.fnum = fnum;
|
7
|
117 vim_free(namedfm[i].fname);
|
|
118 namedfm[i].fname = NULL;
|
|
119 return OK;
|
|
120 }
|
|
121 return FAIL;
|
|
122 }
|
|
123
|
|
124 /*
|
|
125 * Set the previous context mark to the current position and add it to the
|
|
126 * jump list.
|
|
127 */
|
|
128 void
|
|
129 setpcmark()
|
|
130 {
|
|
131 #ifdef FEAT_JUMPLIST
|
|
132 int i;
|
|
133 xfmark_T *fm;
|
|
134 #endif
|
|
135 #ifdef JUMPLIST_ROTATE
|
|
136 xfmark_T tempmark;
|
|
137 #endif
|
|
138
|
|
139 /* for :global the mark is set only once */
|
|
140 if (global_busy || listcmd_busy || cmdmod.keepjumps)
|
|
141 return;
|
|
142
|
|
143 curwin->w_prev_pcmark = curwin->w_pcmark;
|
|
144 curwin->w_pcmark = curwin->w_cursor;
|
|
145
|
|
146 #ifdef FEAT_JUMPLIST
|
|
147 # ifdef JUMPLIST_ROTATE
|
|
148 /*
|
|
149 * If last used entry is not at the top, put it at the top by rotating
|
|
150 * the stack until it is (the newer entries will be at the bottom).
|
|
151 * Keep one entry (the last used one) at the top.
|
|
152 */
|
|
153 if (curwin->w_jumplistidx < curwin->w_jumplistlen)
|
|
154 ++curwin->w_jumplistidx;
|
|
155 while (curwin->w_jumplistidx < curwin->w_jumplistlen)
|
|
156 {
|
|
157 tempmark = curwin->w_jumplist[curwin->w_jumplistlen - 1];
|
|
158 for (i = curwin->w_jumplistlen - 1; i > 0; --i)
|
|
159 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1];
|
|
160 curwin->w_jumplist[0] = tempmark;
|
|
161 ++curwin->w_jumplistidx;
|
|
162 }
|
|
163 # endif
|
|
164
|
|
165 /* If jumplist is full: remove oldest entry */
|
|
166 if (++curwin->w_jumplistlen > JUMPLISTSIZE)
|
|
167 {
|
|
168 curwin->w_jumplistlen = JUMPLISTSIZE;
|
|
169 vim_free(curwin->w_jumplist[0].fname);
|
|
170 for (i = 1; i < JUMPLISTSIZE; ++i)
|
|
171 curwin->w_jumplist[i - 1] = curwin->w_jumplist[i];
|
|
172 }
|
|
173 curwin->w_jumplistidx = curwin->w_jumplistlen;
|
|
174 fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
|
|
175
|
|
176 fm->fmark.mark = curwin->w_pcmark;
|
|
177 fm->fmark.fnum = curbuf->b_fnum;
|
|
178 fm->fname = NULL;
|
|
179 #endif
|
|
180 }
|
|
181
|
|
182 /*
|
|
183 * To change context, call setpcmark(), then move the current position to
|
|
184 * where ever, then call checkpcmark(). This ensures that the previous
|
|
185 * context will only be changed if the cursor moved to a different line.
|
|
186 * If pcmark was deleted (with "dG") the previous mark is restored.
|
|
187 */
|
|
188 void
|
|
189 checkpcmark()
|
|
190 {
|
|
191 if (curwin->w_prev_pcmark.lnum != 0
|
|
192 && (equalpos(curwin->w_pcmark, curwin->w_cursor)
|
|
193 || curwin->w_pcmark.lnum == 0))
|
|
194 {
|
|
195 curwin->w_pcmark = curwin->w_prev_pcmark;
|
|
196 curwin->w_prev_pcmark.lnum = 0; /* Show it has been checked */
|
|
197 }
|
|
198 }
|
|
199
|
|
200 #if defined(FEAT_JUMPLIST) || defined(PROTO)
|
|
201 /*
|
|
202 * move "count" positions in the jump list (count may be negative)
|
|
203 */
|
|
204 pos_T *
|
|
205 movemark(count)
|
|
206 int count;
|
|
207 {
|
|
208 pos_T *pos;
|
|
209 xfmark_T *jmp;
|
|
210
|
|
211 cleanup_jumplist();
|
|
212
|
|
213 if (curwin->w_jumplistlen == 0) /* nothing to jump to */
|
|
214 return (pos_T *)NULL;
|
|
215
|
|
216 for (;;)
|
|
217 {
|
|
218 if (curwin->w_jumplistidx + count < 0
|
|
219 || curwin->w_jumplistidx + count >= curwin->w_jumplistlen)
|
|
220 return (pos_T *)NULL;
|
|
221
|
|
222 /*
|
|
223 * if first CTRL-O or CTRL-I command after a jump, add cursor position
|
1188
|
224 * to list. Careful: If there are duplicates (CTRL-O immediately after
|
7
|
225 * starting Vim on a file), another entry may have been removed.
|
|
226 */
|
|
227 if (curwin->w_jumplistidx == curwin->w_jumplistlen)
|
|
228 {
|
|
229 setpcmark();
|
|
230 --curwin->w_jumplistidx; /* skip the new entry */
|
|
231 if (curwin->w_jumplistidx + count < 0)
|
|
232 return (pos_T *)NULL;
|
|
233 }
|
|
234
|
|
235 curwin->w_jumplistidx += count;
|
|
236
|
|
237 jmp = curwin->w_jumplist + curwin->w_jumplistidx;
|
|
238 if (jmp->fmark.fnum == 0)
|
|
239 fname2fnum(jmp);
|
|
240 if (jmp->fmark.fnum != curbuf->b_fnum)
|
|
241 {
|
|
242 /* jump to other file */
|
|
243 if (buflist_findnr(jmp->fmark.fnum) == NULL)
|
|
244 { /* Skip this one .. */
|
|
245 count += count < 0 ? -1 : 1;
|
|
246 continue;
|
|
247 }
|
|
248 if (buflist_getfile(jmp->fmark.fnum, jmp->fmark.mark.lnum,
|
|
249 0, FALSE) == FAIL)
|
|
250 return (pos_T *)NULL;
|
|
251 /* Set lnum again, autocommands my have changed it */
|
|
252 curwin->w_cursor = jmp->fmark.mark;
|
|
253 pos = (pos_T *)-1;
|
|
254 }
|
|
255 else
|
|
256 pos = &(jmp->fmark.mark);
|
|
257 return pos;
|
|
258 }
|
|
259 }
|
|
260
|
|
261 /*
|
|
262 * Move "count" positions in the changelist (count may be negative).
|
|
263 */
|
|
264 pos_T *
|
|
265 movechangelist(count)
|
|
266 int count;
|
|
267 {
|
|
268 int n;
|
|
269
|
|
270 if (curbuf->b_changelistlen == 0) /* nothing to jump to */
|
|
271 return (pos_T *)NULL;
|
|
272
|
|
273 n = curwin->w_changelistidx;
|
|
274 if (n + count < 0)
|
|
275 {
|
|
276 if (n == 0)
|
|
277 return (pos_T *)NULL;
|
|
278 n = 0;
|
|
279 }
|
|
280 else if (n + count >= curbuf->b_changelistlen)
|
|
281 {
|
|
282 if (n == curbuf->b_changelistlen - 1)
|
|
283 return (pos_T *)NULL;
|
|
284 n = curbuf->b_changelistlen - 1;
|
|
285 }
|
|
286 else
|
|
287 n += count;
|
|
288 curwin->w_changelistidx = n;
|
|
289 return curbuf->b_changelist + n;
|
|
290 }
|
|
291 #endif
|
|
292
|
|
293 /*
|
|
294 * Find mark "c".
|
706
|
295 * If "changefile" is TRUE it's allowed to edit another file for '0, 'A, etc.
|
|
296 * If "fnum" is not NULL store the fnum there for '0, 'A etc., don't edit
|
|
297 * another file.
|
7
|
298 * Returns:
|
|
299 * - pointer to pos_T if found. lnum is 0 when mark not set, -1 when mark is
|
|
300 * in another file which can't be gotten. (caller needs to check lnum!)
|
|
301 * - NULL if there is no mark called 'c'.
|
|
302 * - -1 if mark is in other file and jumped there (only if changefile is TRUE)
|
|
303 */
|
|
304 pos_T *
|
|
305 getmark(c, changefile)
|
|
306 int c;
|
706
|
307 int changefile;
|
|
308 {
|
|
309 return getmark_fnum(c, changefile, NULL);
|
|
310 }
|
|
311
|
|
312 pos_T *
|
|
313 getmark_fnum(c, changefile, fnum)
|
|
314 int c;
|
|
315 int changefile;
|
|
316 int *fnum;
|
7
|
317 {
|
|
318 pos_T *posp;
|
|
319 #ifdef FEAT_VISUAL
|
|
320 pos_T *startp, *endp;
|
|
321 #endif
|
|
322 static pos_T pos_copy;
|
|
323
|
|
324 posp = NULL;
|
|
325
|
|
326 /* Check for special key, can't be a mark name and might cause islower()
|
|
327 * to crash. */
|
|
328 if (c < 0)
|
|
329 return posp;
|
|
330 #ifndef EBCDIC
|
|
331 if (c > '~') /* check for islower()/isupper() */
|
|
332 ;
|
|
333 else
|
|
334 #endif
|
|
335 if (c == '\'' || c == '`') /* previous context mark */
|
|
336 {
|
|
337 pos_copy = curwin->w_pcmark; /* need to make a copy because */
|
|
338 posp = &pos_copy; /* w_pcmark may be changed soon */
|
|
339 }
|
|
340 else if (c == '"') /* to pos when leaving buffer */
|
|
341 posp = &(curbuf->b_last_cursor);
|
|
342 else if (c == '^') /* to where Insert mode stopped */
|
|
343 posp = &(curbuf->b_last_insert);
|
|
344 else if (c == '.') /* to where last change was made */
|
|
345 posp = &(curbuf->b_last_change);
|
|
346 else if (c == '[') /* to start of previous operator */
|
|
347 posp = &(curbuf->b_op_start);
|
|
348 else if (c == ']') /* to end of previous operator */
|
|
349 posp = &(curbuf->b_op_end);
|
|
350 else if (c == '{' || c == '}') /* to previous/next paragraph */
|
|
351 {
|
|
352 pos_T pos;
|
|
353 oparg_T oa;
|
|
354 int slcb = listcmd_busy;
|
|
355
|
|
356 pos = curwin->w_cursor;
|
|
357 listcmd_busy = TRUE; /* avoid that '' is changed */
|
503
|
358 if (findpar(&oa.inclusive,
|
|
359 c == '}' ? FORWARD : BACKWARD, 1L, NUL, FALSE))
|
7
|
360 {
|
|
361 pos_copy = curwin->w_cursor;
|
|
362 posp = &pos_copy;
|
|
363 }
|
|
364 curwin->w_cursor = pos;
|
|
365 listcmd_busy = slcb;
|
|
366 }
|
|
367 else if (c == '(' || c == ')') /* to previous/next sentence */
|
|
368 {
|
|
369 pos_T pos;
|
|
370 int slcb = listcmd_busy;
|
|
371
|
|
372 pos = curwin->w_cursor;
|
|
373 listcmd_busy = TRUE; /* avoid that '' is changed */
|
|
374 if (findsent(c == ')' ? FORWARD : BACKWARD, 1L))
|
|
375 {
|
|
376 pos_copy = curwin->w_cursor;
|
|
377 posp = &pos_copy;
|
|
378 }
|
|
379 curwin->w_cursor = pos;
|
|
380 listcmd_busy = slcb;
|
|
381 }
|
|
382 #ifdef FEAT_VISUAL
|
|
383 else if (c == '<' || c == '>') /* start/end of visual area */
|
|
384 {
|
690
|
385 startp = &curbuf->b_visual.vi_start;
|
|
386 endp = &curbuf->b_visual.vi_end;
|
7
|
387 if ((c == '<') == lt(*startp, *endp))
|
|
388 posp = startp;
|
|
389 else
|
|
390 posp = endp;
|
|
391 /*
|
|
392 * For Visual line mode, set mark at begin or end of line
|
|
393 */
|
690
|
394 if (curbuf->b_visual.vi_mode == 'V')
|
7
|
395 {
|
|
396 pos_copy = *posp;
|
|
397 posp = &pos_copy;
|
|
398 if (c == '<')
|
|
399 pos_copy.col = 0;
|
|
400 else
|
|
401 pos_copy.col = MAXCOL;
|
|
402 #ifdef FEAT_VIRTUALEDIT
|
|
403 pos_copy.coladd = 0;
|
|
404 #endif
|
|
405 }
|
|
406 }
|
|
407 #endif
|
|
408 else if (ASCII_ISLOWER(c)) /* normal named mark */
|
|
409 {
|
|
410 posp = &(curbuf->b_namedm[c - 'a']);
|
|
411 }
|
|
412 else if (ASCII_ISUPPER(c) || VIM_ISDIGIT(c)) /* named file mark */
|
|
413 {
|
|
414 if (VIM_ISDIGIT(c))
|
|
415 c = c - '0' + NMARKS;
|
|
416 else
|
|
417 c -= 'A';
|
|
418 posp = &(namedfm[c].fmark.mark);
|
|
419
|
|
420 if (namedfm[c].fmark.fnum == 0)
|
|
421 fname2fnum(&namedfm[c]);
|
706
|
422
|
|
423 if (fnum != NULL)
|
|
424 *fnum = namedfm[c].fmark.fnum;
|
|
425 else if (namedfm[c].fmark.fnum != curbuf->b_fnum)
|
7
|
426 {
|
706
|
427 /* mark is in another file */
|
7
|
428 posp = &pos_copy;
|
|
429
|
|
430 if (namedfm[c].fmark.mark.lnum != 0
|
|
431 && changefile && namedfm[c].fmark.fnum)
|
|
432 {
|
|
433 if (buflist_getfile(namedfm[c].fmark.fnum,
|
|
434 (linenr_T)1, GETF_SETMARK, FALSE) == OK)
|
|
435 {
|
|
436 /* Set the lnum now, autocommands could have changed it */
|
|
437 curwin->w_cursor = namedfm[c].fmark.mark;
|
|
438 return (pos_T *)-1;
|
|
439 }
|
|
440 pos_copy.lnum = -1; /* can't get file */
|
|
441 }
|
|
442 else
|
|
443 pos_copy.lnum = 0; /* mark exists, but is not valid in
|
|
444 current buffer */
|
|
445 }
|
|
446 }
|
|
447
|
|
448 return posp;
|
|
449 }
|
|
450
|
|
451 /*
|
|
452 * Search for the next named mark in the current file.
|
|
453 *
|
|
454 * Returns pointer to pos_T of the next mark or NULL if no mark is found.
|
|
455 */
|
|
456 pos_T *
|
|
457 getnextmark(startpos, dir, begin_line)
|
|
458 pos_T *startpos; /* where to start */
|
|
459 int dir; /* direction for search */
|
|
460 int begin_line;
|
|
461 {
|
|
462 int i;
|
|
463 pos_T *result = NULL;
|
|
464 pos_T pos;
|
|
465
|
|
466 pos = *startpos;
|
|
467
|
|
468 /* When searching backward and leaving the cursor on the first non-blank,
|
|
469 * position must be in a previous line.
|
|
470 * When searching forward and leaving the cursor on the first non-blank,
|
|
471 * position must be in a next line. */
|
|
472 if (dir == BACKWARD && begin_line)
|
|
473 pos.col = 0;
|
|
474 else if (dir == FORWARD && begin_line)
|
|
475 pos.col = MAXCOL;
|
|
476
|
|
477 for (i = 0; i < NMARKS; i++)
|
|
478 {
|
|
479 if (curbuf->b_namedm[i].lnum > 0)
|
|
480 {
|
|
481 if (dir == FORWARD)
|
|
482 {
|
|
483 if ((result == NULL || lt(curbuf->b_namedm[i], *result))
|
|
484 && lt(pos, curbuf->b_namedm[i]))
|
|
485 result = &curbuf->b_namedm[i];
|
|
486 }
|
|
487 else
|
|
488 {
|
|
489 if ((result == NULL || lt(*result, curbuf->b_namedm[i]))
|
|
490 && lt(curbuf->b_namedm[i], pos))
|
|
491 result = &curbuf->b_namedm[i];
|
|
492 }
|
|
493 }
|
|
494 }
|
|
495
|
|
496 return result;
|
|
497 }
|
|
498
|
|
499 /*
|
|
500 * For an xtended filemark: set the fnum from the fname.
|
|
501 * This is used for marks obtained from the .viminfo file. It's postponed
|
|
502 * until the mark is used to avoid a long startup delay.
|
|
503 */
|
|
504 static void
|
|
505 fname2fnum(fm)
|
|
506 xfmark_T *fm;
|
|
507 {
|
|
508 char_u *p;
|
|
509
|
|
510 if (fm->fname != NULL)
|
|
511 {
|
|
512 /*
|
|
513 * First expand "~/" in the file name to the home directory.
|
1480
|
514 * Don't expand the whole name, it may contain other '~' chars.
|
7
|
515 */
|
1480
|
516 if (fm->fname[0] == '~' && (fm->fname[1] == '/'
|
|
517 #ifdef BACKSLASH_IN_FILENAME
|
|
518 || fm->fname[1] == '\\'
|
|
519 #endif
|
|
520 ))
|
|
521 {
|
|
522 int len;
|
|
523
|
|
524 expand_env((char_u *)"~/", NameBuff, MAXPATHL);
|
1570
|
525 len = (int)STRLEN(NameBuff);
|
1480
|
526 vim_strncpy(NameBuff + len, fm->fname + 2, MAXPATHL - len - 1);
|
|
527 }
|
|
528 else
|
|
529 vim_strncpy(NameBuff, fm->fname, MAXPATHL - 1);
|
|
530
|
|
531 /* Try to shorten the file name. */
|
7
|
532 mch_dirname(IObuff, IOSIZE);
|
|
533 p = shorten_fname(NameBuff, IObuff);
|
|
534
|
|
535 /* buflist_new() will call fmarks_check_names() */
|
|
536 (void)buflist_new(NameBuff, p, (linenr_T)1, 0);
|
|
537 }
|
|
538 }
|
|
539
|
|
540 /*
|
|
541 * Check all file marks for a name that matches the file name in buf.
|
|
542 * May replace the name with an fnum.
|
|
543 * Used for marks that come from the .viminfo file.
|
|
544 */
|
|
545 void
|
|
546 fmarks_check_names(buf)
|
|
547 buf_T *buf;
|
|
548 {
|
|
549 char_u *name;
|
|
550 int i;
|
|
551 #ifdef FEAT_JUMPLIST
|
|
552 win_T *wp;
|
|
553 #endif
|
|
554
|
|
555 if (buf->b_ffname == NULL)
|
|
556 return;
|
|
557
|
|
558 name = home_replace_save(buf, buf->b_ffname);
|
|
559 if (name == NULL)
|
|
560 return;
|
|
561
|
|
562 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
|
|
563 fmarks_check_one(&namedfm[i], name, buf);
|
|
564
|
|
565 #ifdef FEAT_JUMPLIST
|
|
566 FOR_ALL_WINDOWS(wp)
|
|
567 {
|
|
568 for (i = 0; i < wp->w_jumplistlen; ++i)
|
|
569 fmarks_check_one(&wp->w_jumplist[i], name, buf);
|
|
570 }
|
|
571 #endif
|
|
572
|
|
573 vim_free(name);
|
|
574 }
|
|
575
|
|
576 static void
|
|
577 fmarks_check_one(fm, name, buf)
|
|
578 xfmark_T *fm;
|
|
579 char_u *name;
|
|
580 buf_T *buf;
|
|
581 {
|
|
582 if (fm->fmark.fnum == 0
|
|
583 && fm->fname != NULL
|
|
584 && fnamecmp(name, fm->fname) == 0)
|
|
585 {
|
|
586 fm->fmark.fnum = buf->b_fnum;
|
|
587 vim_free(fm->fname);
|
|
588 fm->fname = NULL;
|
|
589 }
|
|
590 }
|
|
591
|
|
592 /*
|
|
593 * Check a if a position from a mark is valid.
|
|
594 * Give and error message and return FAIL if not.
|
|
595 */
|
|
596 int
|
|
597 check_mark(pos)
|
|
598 pos_T *pos;
|
|
599 {
|
|
600 if (pos == NULL)
|
|
601 {
|
|
602 EMSG(_(e_umark));
|
|
603 return FAIL;
|
|
604 }
|
|
605 if (pos->lnum <= 0)
|
|
606 {
|
|
607 /* lnum is negative if mark is in another file can can't get that
|
|
608 * file, error message already give then. */
|
|
609 if (pos->lnum == 0)
|
|
610 EMSG(_(e_marknotset));
|
|
611 return FAIL;
|
|
612 }
|
|
613 if (pos->lnum > curbuf->b_ml.ml_line_count)
|
|
614 {
|
|
615 EMSG(_(e_markinval));
|
|
616 return FAIL;
|
|
617 }
|
|
618 return OK;
|
|
619 }
|
|
620
|
|
621 /*
|
|
622 * clrallmarks() - clear all marks in the buffer 'buf'
|
|
623 *
|
|
624 * Used mainly when trashing the entire buffer during ":e" type commands
|
|
625 */
|
|
626 void
|
|
627 clrallmarks(buf)
|
|
628 buf_T *buf;
|
|
629 {
|
|
630 static int i = -1;
|
|
631
|
|
632 if (i == -1) /* first call ever: initialize */
|
|
633 for (i = 0; i < NMARKS + 1; i++)
|
|
634 {
|
|
635 namedfm[i].fmark.mark.lnum = 0;
|
|
636 namedfm[i].fname = NULL;
|
|
637 }
|
|
638
|
|
639 for (i = 0; i < NMARKS; i++)
|
|
640 buf->b_namedm[i].lnum = 0;
|
|
641 buf->b_op_start.lnum = 0; /* start/end op mark cleared */
|
|
642 buf->b_op_end.lnum = 0;
|
|
643 buf->b_last_cursor.lnum = 1; /* '" mark cleared */
|
|
644 buf->b_last_cursor.col = 0;
|
|
645 #ifdef FEAT_VIRTUALEDIT
|
|
646 buf->b_last_cursor.coladd = 0;
|
|
647 #endif
|
|
648 buf->b_last_insert.lnum = 0; /* '^ mark cleared */
|
|
649 buf->b_last_change.lnum = 0; /* '. mark cleared */
|
|
650 #ifdef FEAT_JUMPLIST
|
|
651 buf->b_changelistlen = 0;
|
|
652 #endif
|
|
653 }
|
|
654
|
|
655 /*
|
|
656 * Get name of file from a filemark.
|
|
657 * When it's in the current buffer, return the text at the mark.
|
|
658 * Returns an allocated string.
|
|
659 */
|
|
660 char_u *
|
|
661 fm_getname(fmark, lead_len)
|
|
662 fmark_T *fmark;
|
|
663 int lead_len;
|
|
664 {
|
|
665 if (fmark->fnum == curbuf->b_fnum) /* current buffer */
|
|
666 return mark_line(&(fmark->mark), lead_len);
|
|
667 return buflist_nr2name(fmark->fnum, FALSE, TRUE);
|
|
668 }
|
|
669
|
|
670 /*
|
|
671 * Return the line at mark "mp". Truncate to fit in window.
|
|
672 * The returned string has been allocated.
|
|
673 */
|
|
674 static char_u *
|
|
675 mark_line(mp, lead_len)
|
|
676 pos_T *mp;
|
|
677 int lead_len;
|
|
678 {
|
|
679 char_u *s, *p;
|
|
680 int len;
|
|
681
|
|
682 if (mp->lnum == 0 || mp->lnum > curbuf->b_ml.ml_line_count)
|
|
683 return vim_strsave((char_u *)"-invalid-");
|
|
684 s = vim_strnsave(skipwhite(ml_get(mp->lnum)), (int)Columns);
|
|
685 if (s == NULL)
|
|
686 return NULL;
|
|
687 /* Truncate the line to fit it in the window */
|
|
688 len = 0;
|
39
|
689 for (p = s; *p != NUL; mb_ptr_adv(p))
|
7
|
690 {
|
|
691 len += ptr2cells(p);
|
|
692 if (len >= Columns - lead_len)
|
|
693 break;
|
|
694 }
|
|
695 *p = NUL;
|
|
696 return s;
|
|
697 }
|
|
698
|
|
699 /*
|
|
700 * print the marks
|
|
701 */
|
|
702 void
|
|
703 do_marks(eap)
|
|
704 exarg_T *eap;
|
|
705 {
|
|
706 char_u *arg = eap->arg;
|
|
707 int i;
|
|
708 char_u *name;
|
|
709
|
|
710 if (arg != NULL && *arg == NUL)
|
|
711 arg = NULL;
|
|
712
|
|
713 show_one_mark('\'', arg, &curwin->w_pcmark, NULL, TRUE);
|
|
714 for (i = 0; i < NMARKS; ++i)
|
|
715 show_one_mark(i + 'a', arg, &curbuf->b_namedm[i], NULL, TRUE);
|
|
716 for (i = 0; i < NMARKS + EXTRA_MARKS; ++i)
|
|
717 {
|
|
718 if (namedfm[i].fmark.fnum != 0)
|
|
719 name = fm_getname(&namedfm[i].fmark, 15);
|
|
720 else
|
|
721 name = namedfm[i].fname;
|
|
722 if (name != NULL)
|
|
723 {
|
|
724 show_one_mark(i >= NMARKS ? i - NMARKS + '0' : i + 'A',
|
|
725 arg, &namedfm[i].fmark.mark, name,
|
|
726 namedfm[i].fmark.fnum == curbuf->b_fnum);
|
|
727 if (namedfm[i].fmark.fnum != 0)
|
|
728 vim_free(name);
|
|
729 }
|
|
730 }
|
|
731 show_one_mark('"', arg, &curbuf->b_last_cursor, NULL, TRUE);
|
|
732 show_one_mark('[', arg, &curbuf->b_op_start, NULL, TRUE);
|
|
733 show_one_mark(']', arg, &curbuf->b_op_end, NULL, TRUE);
|
|
734 show_one_mark('^', arg, &curbuf->b_last_insert, NULL, TRUE);
|
|
735 show_one_mark('.', arg, &curbuf->b_last_change, NULL, TRUE);
|
|
736 #ifdef FEAT_VISUAL
|
690
|
737 show_one_mark('<', arg, &curbuf->b_visual.vi_start, NULL, TRUE);
|
|
738 show_one_mark('>', arg, &curbuf->b_visual.vi_end, NULL, TRUE);
|
7
|
739 #endif
|
|
740 show_one_mark(-1, arg, NULL, NULL, FALSE);
|
|
741 }
|
|
742
|
|
743 static void
|
|
744 show_one_mark(c, arg, p, name, current)
|
|
745 int c;
|
|
746 char_u *arg;
|
|
747 pos_T *p;
|
|
748 char_u *name;
|
|
749 int current; /* in current file */
|
|
750 {
|
|
751 static int did_title = FALSE;
|
|
752 int mustfree = FALSE;
|
|
753
|
|
754 if (c == -1) /* finish up */
|
|
755 {
|
|
756 if (did_title)
|
|
757 did_title = FALSE;
|
|
758 else
|
|
759 {
|
|
760 if (arg == NULL)
|
|
761 MSG(_("No marks set"));
|
|
762 else
|
|
763 EMSG2(_("E283: No marks matching \"%s\""), arg);
|
|
764 }
|
|
765 }
|
|
766 /* don't output anything if 'q' typed at --more-- prompt */
|
|
767 else if (!got_int
|
|
768 && (arg == NULL || vim_strchr(arg, c) != NULL)
|
|
769 && p->lnum != 0)
|
|
770 {
|
|
771 if (!did_title)
|
|
772 {
|
|
773 /* Highlight title */
|
|
774 MSG_PUTS_TITLE(_("\nmark line col file/text"));
|
|
775 did_title = TRUE;
|
|
776 }
|
|
777 msg_putchar('\n');
|
|
778 if (!got_int)
|
|
779 {
|
|
780 sprintf((char *)IObuff, " %c %6ld %4d ", c, p->lnum, p->col);
|
|
781 msg_outtrans(IObuff);
|
|
782 if (name == NULL && current)
|
|
783 {
|
|
784 name = mark_line(p, 15);
|
|
785 mustfree = TRUE;
|
|
786 }
|
|
787 if (name != NULL)
|
|
788 {
|
|
789 msg_outtrans_attr(name, current ? hl_attr(HLF_D) : 0);
|
|
790 if (mustfree)
|
|
791 vim_free(name);
|
|
792 }
|
|
793 }
|
|
794 out_flush(); /* show one line at a time */
|
|
795 }
|
|
796 }
|
|
797
|
24
|
798 /*
|
|
799 * ":delmarks[!] [marks]"
|
|
800 */
|
|
801 void
|
|
802 ex_delmarks(eap)
|
|
803 exarg_T *eap;
|
|
804 {
|
|
805 char_u *p;
|
|
806 int from, to;
|
|
807 int i;
|
|
808 int lower;
|
|
809 int digit;
|
|
810 int n;
|
|
811
|
|
812 if (*eap->arg == NUL && eap->forceit)
|
|
813 /* clear all marks */
|
|
814 clrallmarks(curbuf);
|
|
815 else if (eap->forceit)
|
|
816 EMSG(_(e_invarg));
|
|
817 else if (*eap->arg == NUL)
|
|
818 EMSG(_(e_argreq));
|
|
819 else
|
|
820 {
|
|
821 /* clear specified marks only */
|
|
822 for (p = eap->arg; *p != NUL; ++p)
|
|
823 {
|
|
824 lower = ASCII_ISLOWER(*p);
|
|
825 digit = VIM_ISDIGIT(*p);
|
|
826 if (lower || digit || ASCII_ISUPPER(*p))
|
|
827 {
|
|
828 if (p[1] == '-')
|
|
829 {
|
|
830 /* clear range of marks */
|
|
831 from = *p;
|
|
832 to = p[2];
|
|
833 if (!(lower ? ASCII_ISLOWER(p[2])
|
|
834 : (digit ? VIM_ISDIGIT(p[2])
|
|
835 : ASCII_ISUPPER(p[2])))
|
|
836 || to < from)
|
|
837 {
|
|
838 EMSG2(_(e_invarg2), p);
|
|
839 return;
|
|
840 }
|
|
841 p += 2;
|
|
842 }
|
|
843 else
|
|
844 /* clear one lower case mark */
|
|
845 from = to = *p;
|
|
846
|
|
847 for (i = from; i <= to; ++i)
|
|
848 {
|
|
849 if (lower)
|
|
850 curbuf->b_namedm[i - 'a'].lnum = 0;
|
|
851 else
|
|
852 {
|
|
853 if (digit)
|
|
854 n = i - '0' + NMARKS;
|
|
855 else
|
|
856 n = i - 'A';
|
|
857 namedfm[n].fmark.mark.lnum = 0;
|
|
858 vim_free(namedfm[n].fname);
|
|
859 namedfm[n].fname = NULL;
|
|
860 }
|
|
861 }
|
|
862 }
|
|
863 else
|
|
864 switch (*p)
|
|
865 {
|
|
866 case '"': curbuf->b_last_cursor.lnum = 0; break;
|
|
867 case '^': curbuf->b_last_insert.lnum = 0; break;
|
|
868 case '.': curbuf->b_last_change.lnum = 0; break;
|
|
869 case '[': curbuf->b_op_start.lnum = 0; break;
|
|
870 case ']': curbuf->b_op_end.lnum = 0; break;
|
|
871 #ifdef FEAT_VISUAL
|
690
|
872 case '<': curbuf->b_visual.vi_start.lnum = 0; break;
|
|
873 case '>': curbuf->b_visual.vi_end.lnum = 0; break;
|
24
|
874 #endif
|
|
875 case ' ': break;
|
|
876 default: EMSG2(_(e_invarg2), p);
|
|
877 return;
|
|
878 }
|
|
879 }
|
|
880 }
|
|
881 }
|
|
882
|
7
|
883 #if defined(FEAT_JUMPLIST) || defined(PROTO)
|
|
884 /*
|
|
885 * print the jumplist
|
|
886 */
|
|
887 /*ARGSUSED*/
|
|
888 void
|
|
889 ex_jumps(eap)
|
|
890 exarg_T *eap;
|
|
891 {
|
|
892 int i;
|
|
893 char_u *name;
|
|
894
|
|
895 cleanup_jumplist();
|
|
896 /* 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)
|
|
910 break;
|
|
911 sprintf((char *)IObuff, "%c %2d %5ld %4d ",
|
|
912 i == curwin->w_jumplistidx ? '>' : ' ',
|
|
913 i > curwin->w_jumplistidx ? i - curwin->w_jumplistidx
|
|
914 : curwin->w_jumplistidx - i,
|
|
915 curwin->w_jumplist[i].fmark.mark.lnum,
|
|
916 curwin->w_jumplist[i].fmark.mark.col);
|
|
917 msg_outtrans(IObuff);
|
|
918 msg_outtrans_attr(name,
|
|
919 curwin->w_jumplist[i].fmark.fnum == curbuf->b_fnum
|
|
920 ? hl_attr(HLF_D) : 0);
|
|
921 vim_free(name);
|
|
922 ui_breakcheck();
|
|
923 }
|
|
924 out_flush();
|
|
925 }
|
|
926 if (curwin->w_jumplistidx == curwin->w_jumplistlen)
|
|
927 MSG_PUTS("\n>");
|
|
928 }
|
|
929
|
|
930 /*
|
|
931 * print the changelist
|
|
932 */
|
|
933 /*ARGSUSED*/
|
|
934 void
|
|
935 ex_changes(eap)
|
|
936 exarg_T *eap;
|
|
937 {
|
|
938 int i;
|
|
939 char_u *name;
|
|
940
|
|
941 /* Highlight title */
|
|
942 MSG_PUTS_TITLE(_("\nchange line col text"));
|
|
943
|
|
944 for (i = 0; i < curbuf->b_changelistlen && !got_int; ++i)
|
|
945 {
|
|
946 if (curbuf->b_changelist[i].lnum != 0)
|
|
947 {
|
|
948 msg_putchar('\n');
|
|
949 if (got_int)
|
|
950 break;
|
|
951 sprintf((char *)IObuff, "%c %3d %5ld %4d ",
|
|
952 i == curwin->w_changelistidx ? '>' : ' ',
|
|
953 i > curwin->w_changelistidx ? i - curwin->w_changelistidx
|
|
954 : curwin->w_changelistidx - i,
|
|
955 (long)curbuf->b_changelist[i].lnum,
|
|
956 curbuf->b_changelist[i].col);
|
|
957 msg_outtrans(IObuff);
|
|
958 name = mark_line(&curbuf->b_changelist[i], 17);
|
|
959 if (name == NULL)
|
|
960 break;
|
|
961 msg_outtrans_attr(name, hl_attr(HLF_D));
|
|
962 vim_free(name);
|
|
963 ui_breakcheck();
|
|
964 }
|
|
965 out_flush();
|
|
966 }
|
|
967 if (curwin->w_changelistidx == curbuf->b_changelistlen)
|
|
968 MSG_PUTS("\n>");
|
|
969 }
|
|
970 #endif
|
|
971
|
|
972 #define one_adjust(add) \
|
|
973 { \
|
|
974 lp = add; \
|
|
975 if (*lp >= line1 && *lp <= line2) \
|
|
976 { \
|
|
977 if (amount == MAXLNUM) \
|
|
978 *lp = 0; \
|
|
979 else \
|
|
980 *lp += amount; \
|
|
981 } \
|
|
982 else if (amount_after && *lp > line2) \
|
|
983 *lp += amount_after; \
|
|
984 }
|
|
985
|
|
986 /* don't delete the line, just put at first deleted line */
|
|
987 #define one_adjust_nodel(add) \
|
|
988 { \
|
|
989 lp = add; \
|
|
990 if (*lp >= line1 && *lp <= line2) \
|
|
991 { \
|
|
992 if (amount == MAXLNUM) \
|
|
993 *lp = line1; \
|
|
994 else \
|
|
995 *lp += amount; \
|
|
996 } \
|
|
997 else if (amount_after && *lp > line2) \
|
|
998 *lp += amount_after; \
|
|
999 }
|
|
1000
|
|
1001 /*
|
|
1002 * Adjust marks between line1 and line2 (inclusive) to move 'amount' lines.
|
|
1003 * Must be called before changed_*(), appended_lines() or deleted_lines().
|
|
1004 * May be called before or after changing the text.
|
|
1005 * When deleting lines line1 to line2, use an 'amount' of MAXLNUM: The marks
|
|
1006 * within this range are made invalid.
|
|
1007 * If 'amount_after' is non-zero adjust marks after line2.
|
|
1008 * Example: Delete lines 34 and 35: mark_adjust(34, 35, MAXLNUM, -2);
|
|
1009 * Example: Insert two lines below 55: mark_adjust(56, MAXLNUM, 2, 0);
|
|
1010 * or: mark_adjust(56, 55, MAXLNUM, 2);
|
|
1011 */
|
|
1012 void
|
|
1013 mark_adjust(line1, line2, amount, amount_after)
|
|
1014 linenr_T line1;
|
|
1015 linenr_T line2;
|
|
1016 long amount;
|
|
1017 long amount_after;
|
|
1018 {
|
|
1019 int i;
|
|
1020 int fnum = curbuf->b_fnum;
|
|
1021 linenr_T *lp;
|
|
1022 win_T *win;
|
|
1023
|
|
1024 if (line2 < line1 && amount_after == 0L) /* nothing to do */
|
|
1025 return;
|
|
1026
|
|
1027 if (!cmdmod.lockmarks)
|
|
1028 {
|
|
1029 /* named marks, lower case and upper case */
|
|
1030 for (i = 0; i < NMARKS; i++)
|
|
1031 {
|
|
1032 one_adjust(&(curbuf->b_namedm[i].lnum));
|
|
1033 if (namedfm[i].fmark.fnum == fnum)
|
|
1034 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
|
|
1035 }
|
|
1036 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
|
|
1037 {
|
|
1038 if (namedfm[i].fmark.fnum == fnum)
|
|
1039 one_adjust_nodel(&(namedfm[i].fmark.mark.lnum));
|
|
1040 }
|
|
1041
|
|
1042 /* last Insert position */
|
|
1043 one_adjust(&(curbuf->b_last_insert.lnum));
|
|
1044
|
|
1045 /* last change position */
|
|
1046 one_adjust(&(curbuf->b_last_change.lnum));
|
|
1047
|
|
1048 #ifdef FEAT_JUMPLIST
|
|
1049 /* list of change positions */
|
|
1050 for (i = 0; i < curbuf->b_changelistlen; ++i)
|
|
1051 one_adjust_nodel(&(curbuf->b_changelist[i].lnum));
|
|
1052 #endif
|
|
1053
|
|
1054 #ifdef FEAT_VISUAL
|
|
1055 /* Visual area */
|
690
|
1056 one_adjust_nodel(&(curbuf->b_visual.vi_start.lnum));
|
|
1057 one_adjust_nodel(&(curbuf->b_visual.vi_end.lnum));
|
7
|
1058 #endif
|
|
1059
|
|
1060 #ifdef FEAT_QUICKFIX
|
|
1061 /* quickfix marks */
|
643
|
1062 qf_mark_adjust(NULL, line1, line2, amount, amount_after);
|
|
1063 /* location lists */
|
|
1064 FOR_ALL_WINDOWS(win)
|
|
1065 qf_mark_adjust(win, line1, line2, amount, amount_after);
|
7
|
1066 #endif
|
|
1067
|
|
1068 #ifdef FEAT_SIGNS
|
|
1069 sign_mark_adjust(line1, line2, amount, amount_after);
|
|
1070 #endif
|
|
1071 }
|
|
1072
|
|
1073 /* previous context mark */
|
|
1074 one_adjust(&(curwin->w_pcmark.lnum));
|
|
1075
|
|
1076 /* previous pcmark */
|
|
1077 one_adjust(&(curwin->w_prev_pcmark.lnum));
|
|
1078
|
|
1079 /* saved cursor for formatting */
|
|
1080 if (saved_cursor.lnum != 0)
|
|
1081 one_adjust_nodel(&(saved_cursor.lnum));
|
|
1082
|
|
1083 /*
|
|
1084 * Adjust items in all windows related to the current buffer.
|
|
1085 */
|
|
1086 FOR_ALL_WINDOWS(win)
|
|
1087 {
|
|
1088 #ifdef FEAT_JUMPLIST
|
|
1089 if (!cmdmod.lockmarks)
|
|
1090 /* Marks in the jumplist. When deleting lines, this may create
|
|
1091 * duplicate marks in the jumplist, they will be removed later. */
|
|
1092 for (i = 0; i < win->w_jumplistlen; ++i)
|
|
1093 if (win->w_jumplist[i].fmark.fnum == fnum)
|
|
1094 one_adjust_nodel(&(win->w_jumplist[i].fmark.mark.lnum));
|
|
1095 #endif
|
|
1096
|
|
1097 if (win->w_buffer == curbuf)
|
|
1098 {
|
|
1099 if (!cmdmod.lockmarks)
|
|
1100 /* marks in the tag stack */
|
|
1101 for (i = 0; i < win->w_tagstacklen; i++)
|
|
1102 if (win->w_tagstack[i].fmark.fnum == fnum)
|
|
1103 one_adjust_nodel(&(win->w_tagstack[i].fmark.mark.lnum));
|
|
1104
|
|
1105 #ifdef FEAT_VISUAL
|
|
1106 /* the displayed Visual area */
|
|
1107 if (win->w_old_cursor_lnum != 0)
|
|
1108 {
|
|
1109 one_adjust_nodel(&(win->w_old_cursor_lnum));
|
|
1110 one_adjust_nodel(&(win->w_old_visual_lnum));
|
|
1111 }
|
|
1112 #endif
|
|
1113
|
|
1114 /* topline and cursor position for windows with the same buffer
|
|
1115 * other than the current window */
|
|
1116 if (win != curwin)
|
|
1117 {
|
|
1118 if (win->w_topline >= line1 && win->w_topline <= line2)
|
|
1119 {
|
|
1120 if (amount == MAXLNUM) /* topline is deleted */
|
|
1121 {
|
|
1122 if (line1 <= 1)
|
|
1123 win->w_topline = 1;
|
|
1124 else
|
|
1125 win->w_topline = line1 - 1;
|
|
1126 }
|
|
1127 else /* keep topline on the same line */
|
|
1128 win->w_topline += amount;
|
|
1129 #ifdef FEAT_DIFF
|
|
1130 win->w_topfill = 0;
|
|
1131 #endif
|
|
1132 }
|
|
1133 else if (amount_after && win->w_topline > line2)
|
|
1134 {
|
|
1135 win->w_topline += amount_after;
|
|
1136 #ifdef FEAT_DIFF
|
|
1137 win->w_topfill = 0;
|
|
1138 #endif
|
|
1139 }
|
|
1140 if (win->w_cursor.lnum >= line1 && win->w_cursor.lnum <= line2)
|
|
1141 {
|
|
1142 if (amount == MAXLNUM) /* line with cursor is deleted */
|
|
1143 {
|
|
1144 if (line1 <= 1)
|
|
1145 win->w_cursor.lnum = 1;
|
|
1146 else
|
|
1147 win->w_cursor.lnum = line1 - 1;
|
|
1148 win->w_cursor.col = 0;
|
|
1149 }
|
|
1150 else /* keep cursor on the same line */
|
|
1151 win->w_cursor.lnum += amount;
|
|
1152 }
|
|
1153 else if (amount_after && win->w_cursor.lnum > line2)
|
|
1154 win->w_cursor.lnum += amount_after;
|
|
1155 }
|
|
1156
|
|
1157 #ifdef FEAT_FOLDING
|
|
1158 /* adjust folds */
|
|
1159 foldMarkAdjust(win, line1, line2, amount, amount_after);
|
|
1160 #endif
|
|
1161 }
|
|
1162 }
|
|
1163
|
|
1164 #ifdef FEAT_DIFF
|
|
1165 /* adjust diffs */
|
|
1166 diff_mark_adjust(line1, line2, amount, amount_after);
|
|
1167 #endif
|
|
1168 }
|
|
1169
|
|
1170 /* This code is used often, needs to be fast. */
|
|
1171 #define col_adjust(pp) \
|
|
1172 { \
|
|
1173 posp = pp; \
|
|
1174 if (posp->lnum == lnum && posp->col >= mincol) \
|
|
1175 { \
|
|
1176 posp->lnum += lnum_amount; \
|
|
1177 if (col_amount < 0 && posp->col <= (colnr_T)-col_amount) \
|
|
1178 posp->col = 0; \
|
|
1179 else \
|
|
1180 posp->col += col_amount; \
|
|
1181 } \
|
|
1182 }
|
|
1183
|
|
1184 /*
|
|
1185 * Adjust marks in line "lnum" at column "mincol" and further: add
|
|
1186 * "lnum_amount" to the line number and add "col_amount" to the column
|
|
1187 * position.
|
|
1188 */
|
|
1189 void
|
|
1190 mark_col_adjust(lnum, mincol, lnum_amount, col_amount)
|
|
1191 linenr_T lnum;
|
|
1192 colnr_T mincol;
|
|
1193 long lnum_amount;
|
|
1194 long col_amount;
|
|
1195 {
|
|
1196 int i;
|
|
1197 int fnum = curbuf->b_fnum;
|
|
1198 win_T *win;
|
|
1199 pos_T *posp;
|
|
1200
|
|
1201 if ((col_amount == 0L && lnum_amount == 0L) || cmdmod.lockmarks)
|
|
1202 return; /* nothing to do */
|
|
1203
|
|
1204 /* named marks, lower case and upper case */
|
|
1205 for (i = 0; i < NMARKS; i++)
|
|
1206 {
|
|
1207 col_adjust(&(curbuf->b_namedm[i]));
|
|
1208 if (namedfm[i].fmark.fnum == fnum)
|
|
1209 col_adjust(&(namedfm[i].fmark.mark));
|
|
1210 }
|
|
1211 for (i = NMARKS; i < NMARKS + EXTRA_MARKS; i++)
|
|
1212 {
|
|
1213 if (namedfm[i].fmark.fnum == fnum)
|
|
1214 col_adjust(&(namedfm[i].fmark.mark));
|
|
1215 }
|
|
1216
|
|
1217 /* last Insert position */
|
|
1218 col_adjust(&(curbuf->b_last_insert));
|
|
1219
|
|
1220 /* last change position */
|
|
1221 col_adjust(&(curbuf->b_last_change));
|
|
1222
|
|
1223 #ifdef FEAT_JUMPLIST
|
|
1224 /* list of change positions */
|
|
1225 for (i = 0; i < curbuf->b_changelistlen; ++i)
|
|
1226 col_adjust(&(curbuf->b_changelist[i]));
|
|
1227 #endif
|
|
1228
|
|
1229 #ifdef FEAT_VISUAL
|
|
1230 /* Visual area */
|
690
|
1231 col_adjust(&(curbuf->b_visual.vi_start));
|
|
1232 col_adjust(&(curbuf->b_visual.vi_end));
|
7
|
1233 #endif
|
|
1234
|
|
1235 /* previous context mark */
|
|
1236 col_adjust(&(curwin->w_pcmark));
|
|
1237
|
|
1238 /* previous pcmark */
|
|
1239 col_adjust(&(curwin->w_prev_pcmark));
|
|
1240
|
|
1241 /* saved cursor for formatting */
|
|
1242 col_adjust(&saved_cursor);
|
|
1243
|
|
1244 /*
|
|
1245 * Adjust items in all windows related to the current buffer.
|
|
1246 */
|
|
1247 FOR_ALL_WINDOWS(win)
|
|
1248 {
|
|
1249 #ifdef FEAT_JUMPLIST
|
|
1250 /* marks in the jumplist */
|
|
1251 for (i = 0; i < win->w_jumplistlen; ++i)
|
|
1252 if (win->w_jumplist[i].fmark.fnum == fnum)
|
|
1253 col_adjust(&(win->w_jumplist[i].fmark.mark));
|
|
1254 #endif
|
|
1255
|
|
1256 if (win->w_buffer == curbuf)
|
|
1257 {
|
|
1258 /* marks in the tag stack */
|
|
1259 for (i = 0; i < win->w_tagstacklen; i++)
|
|
1260 if (win->w_tagstack[i].fmark.fnum == fnum)
|
|
1261 col_adjust(&(win->w_tagstack[i].fmark.mark));
|
|
1262
|
|
1263 /* cursor position for other windows with the same buffer */
|
|
1264 if (win != curwin)
|
|
1265 col_adjust(&win->w_cursor);
|
|
1266 }
|
|
1267 }
|
|
1268 }
|
|
1269
|
|
1270 #ifdef FEAT_JUMPLIST
|
|
1271 /*
|
|
1272 * When deleting lines, this may create duplicate marks in the
|
|
1273 * jumplist. They will be removed here for the current window.
|
|
1274 */
|
|
1275 static void
|
|
1276 cleanup_jumplist()
|
|
1277 {
|
|
1278 int i;
|
|
1279 int from, to;
|
|
1280
|
|
1281 to = 0;
|
|
1282 for (from = 0; from < curwin->w_jumplistlen; ++from)
|
|
1283 {
|
|
1284 if (curwin->w_jumplistidx == from)
|
|
1285 curwin->w_jumplistidx = to;
|
|
1286 for (i = from + 1; i < curwin->w_jumplistlen; ++i)
|
|
1287 if (curwin->w_jumplist[i].fmark.fnum
|
|
1288 == curwin->w_jumplist[from].fmark.fnum
|
|
1289 && curwin->w_jumplist[from].fmark.fnum != 0
|
|
1290 && curwin->w_jumplist[i].fmark.mark.lnum
|
|
1291 == curwin->w_jumplist[from].fmark.mark.lnum)
|
|
1292 break;
|
|
1293 if (i >= curwin->w_jumplistlen) /* no duplicate */
|
|
1294 curwin->w_jumplist[to++] = curwin->w_jumplist[from];
|
|
1295 else
|
|
1296 vim_free(curwin->w_jumplist[from].fname);
|
|
1297 }
|
|
1298 if (curwin->w_jumplistidx == curwin->w_jumplistlen)
|
|
1299 curwin->w_jumplistidx = to;
|
|
1300 curwin->w_jumplistlen = to;
|
|
1301 }
|
|
1302
|
|
1303 # if defined(FEAT_WINDOWS) || defined(PROTO)
|
|
1304 /*
|
|
1305 * Copy the jumplist from window "from" to window "to".
|
|
1306 */
|
|
1307 void
|
|
1308 copy_jumplist(from, to)
|
|
1309 win_T *from;
|
|
1310 win_T *to;
|
|
1311 {
|
|
1312 int i;
|
|
1313
|
|
1314 for (i = 0; i < from->w_jumplistlen; ++i)
|
|
1315 {
|
|
1316 to->w_jumplist[i] = from->w_jumplist[i];
|
|
1317 if (from->w_jumplist[i].fname != NULL)
|
|
1318 to->w_jumplist[i].fname = vim_strsave(from->w_jumplist[i].fname);
|
|
1319 }
|
|
1320 to->w_jumplistlen = from->w_jumplistlen;
|
|
1321 to->w_jumplistidx = from->w_jumplistidx;
|
|
1322 }
|
|
1323
|
|
1324 /*
|
|
1325 * Free items in the jumplist of window "wp".
|
|
1326 */
|
|
1327 void
|
|
1328 free_jumplist(wp)
|
|
1329 win_T *wp;
|
|
1330 {
|
|
1331 int i;
|
|
1332
|
|
1333 for (i = 0; i < wp->w_jumplistlen; ++i)
|
|
1334 vim_free(wp->w_jumplist[i].fname);
|
|
1335 }
|
|
1336 # endif
|
|
1337 #endif /* FEAT_JUMPLIST */
|
|
1338
|
|
1339 void
|
|
1340 set_last_cursor(win)
|
|
1341 win_T *win;
|
|
1342 {
|
|
1343 win->w_buffer->b_last_cursor = win->w_cursor;
|
|
1344 }
|
|
1345
|
358
|
1346 #if defined(EXITFREE) || defined(PROTO)
|
|
1347 void
|
|
1348 free_all_marks()
|
|
1349 {
|
|
1350 int i;
|
|
1351
|
|
1352 for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
|
|
1353 if (namedfm[i].fmark.mark.lnum != 0)
|
|
1354 vim_free(namedfm[i].fname);
|
|
1355 }
|
|
1356 #endif
|
|
1357
|
7
|
1358 #if defined(FEAT_VIMINFO) || defined(PROTO)
|
|
1359 int
|
|
1360 read_viminfo_filemark(virp, force)
|
|
1361 vir_T *virp;
|
|
1362 int force;
|
|
1363 {
|
|
1364 char_u *str;
|
|
1365 xfmark_T *fm;
|
|
1366 int i;
|
|
1367
|
|
1368 /* We only get here if line[0] == '\'' or '-'.
|
|
1369 * Illegal mark names are ignored (for future expansion). */
|
|
1370 str = virp->vir_line + 1;
|
|
1371 if (
|
|
1372 #ifndef EBCDIC
|
|
1373 *str <= 127 &&
|
|
1374 #endif
|
|
1375 ((*virp->vir_line == '\'' && (VIM_ISDIGIT(*str) || isupper(*str)))
|
|
1376 || (*virp->vir_line == '-' && *str == '\'')))
|
|
1377 {
|
|
1378 if (*str == '\'')
|
|
1379 {
|
|
1380 #ifdef FEAT_JUMPLIST
|
|
1381 /* If the jumplist isn't full insert fmark as oldest entry */
|
|
1382 if (curwin->w_jumplistlen == JUMPLISTSIZE)
|
|
1383 fm = NULL;
|
|
1384 else
|
|
1385 {
|
|
1386 for (i = curwin->w_jumplistlen; i > 0; --i)
|
|
1387 curwin->w_jumplist[i] = curwin->w_jumplist[i - 1];
|
|
1388 ++curwin->w_jumplistidx;
|
|
1389 ++curwin->w_jumplistlen;
|
|
1390 fm = &curwin->w_jumplist[0];
|
|
1391 fm->fmark.mark.lnum = 0;
|
|
1392 fm->fname = NULL;
|
|
1393 }
|
|
1394 #else
|
|
1395 fm = NULL;
|
|
1396 #endif
|
|
1397 }
|
|
1398 else if (VIM_ISDIGIT(*str))
|
|
1399 fm = &namedfm[*str - '0' + NMARKS];
|
|
1400 else
|
|
1401 fm = &namedfm[*str - 'A'];
|
|
1402 if (fm != NULL && (fm->fmark.mark.lnum == 0 || force))
|
|
1403 {
|
|
1404 str = skipwhite(str + 1);
|
|
1405 fm->fmark.mark.lnum = getdigits(&str);
|
|
1406 str = skipwhite(str);
|
|
1407 fm->fmark.mark.col = getdigits(&str);
|
|
1408 #ifdef FEAT_VIRTUALEDIT
|
|
1409 fm->fmark.mark.coladd = 0;
|
|
1410 #endif
|
|
1411 fm->fmark.fnum = 0;
|
|
1412 str = skipwhite(str);
|
|
1413 vim_free(fm->fname);
|
|
1414 fm->fname = viminfo_readstring(virp, (int)(str - virp->vir_line),
|
|
1415 FALSE);
|
|
1416 }
|
|
1417 }
|
|
1418 return vim_fgets(virp->vir_line, LSIZE, virp->vir_fd);
|
|
1419 }
|
|
1420
|
|
1421 void
|
|
1422 write_viminfo_filemarks(fp)
|
|
1423 FILE *fp;
|
|
1424 {
|
|
1425 int i;
|
|
1426 char_u *name;
|
|
1427 buf_T *buf;
|
|
1428 xfmark_T *fm;
|
|
1429
|
|
1430 if (get_viminfo_parameter('f') == 0)
|
|
1431 return;
|
|
1432
|
|
1433 fprintf(fp, _("\n# File marks:\n"));
|
|
1434
|
|
1435 /*
|
|
1436 * Find a mark that is the same file and position as the cursor.
|
|
1437 * That one, or else the last one is deleted.
|
|
1438 * Move '0 to '1, '1 to '2, etc. until the matching one or '9
|
|
1439 * Set '0 mark to current cursor position.
|
|
1440 */
|
|
1441 if (curbuf->b_ffname != NULL && !removable(curbuf->b_ffname))
|
|
1442 {
|
|
1443 name = buflist_nr2name(curbuf->b_fnum, TRUE, FALSE);
|
|
1444 for (i = NMARKS; i < NMARKS + EXTRA_MARKS - 1; ++i)
|
|
1445 if (namedfm[i].fmark.mark.lnum == curwin->w_cursor.lnum
|
|
1446 && (namedfm[i].fname == NULL
|
|
1447 ? namedfm[i].fmark.fnum == curbuf->b_fnum
|
|
1448 : (name != NULL
|
|
1449 && STRCMP(name, namedfm[i].fname) == 0)))
|
|
1450 break;
|
|
1451 vim_free(name);
|
|
1452
|
|
1453 vim_free(namedfm[i].fname);
|
|
1454 for ( ; i > NMARKS; --i)
|
|
1455 namedfm[i] = namedfm[i - 1];
|
|
1456 namedfm[NMARKS].fmark.mark = curwin->w_cursor;
|
|
1457 namedfm[NMARKS].fmark.fnum = curbuf->b_fnum;
|
|
1458 namedfm[NMARKS].fname = NULL;
|
|
1459 }
|
|
1460
|
|
1461 /* Write the filemarks '0 - '9 and 'A - 'Z */
|
|
1462 for (i = 0; i < NMARKS + EXTRA_MARKS; i++)
|
|
1463 write_one_filemark(fp, &namedfm[i], '\'',
|
|
1464 i < NMARKS ? i + 'A' : i - NMARKS + '0');
|
|
1465
|
|
1466 #ifdef FEAT_JUMPLIST
|
|
1467 /* Write the jumplist with -' */
|
|
1468 fprintf(fp, _("\n# Jumplist (newest first):\n"));
|
|
1469 setpcmark(); /* add current cursor position */
|
|
1470 cleanup_jumplist();
|
|
1471 for (fm = &curwin->w_jumplist[curwin->w_jumplistlen - 1];
|
|
1472 fm >= &curwin->w_jumplist[0]; --fm)
|
|
1473 {
|
|
1474 if (fm->fmark.fnum == 0
|
|
1475 || ((buf = buflist_findnr(fm->fmark.fnum)) != NULL
|
|
1476 && !removable(buf->b_ffname)))
|
|
1477 write_one_filemark(fp, fm, '-', '\'');
|
|
1478 }
|
|
1479 #endif
|
|
1480 }
|
|
1481
|
|
1482 static void
|
|
1483 write_one_filemark(fp, fm, c1, c2)
|
|
1484 FILE *fp;
|
|
1485 xfmark_T *fm;
|
|
1486 int c1;
|
|
1487 int c2;
|
|
1488 {
|
|
1489 char_u *name;
|
|
1490
|
|
1491 if (fm->fmark.mark.lnum == 0) /* not set */
|
|
1492 return;
|
|
1493
|
|
1494 if (fm->fmark.fnum != 0) /* there is a buffer */
|
|
1495 name = buflist_nr2name(fm->fmark.fnum, TRUE, FALSE);
|
|
1496 else
|
|
1497 name = fm->fname; /* use name from .viminfo */
|
|
1498 if (name != NULL && *name != NUL)
|
|
1499 {
|
|
1500 fprintf(fp, "%c%c %ld %ld ", c1, c2, (long)fm->fmark.mark.lnum,
|
|
1501 (long)fm->fmark.mark.col);
|
|
1502 viminfo_writestring(fp, name);
|
|
1503 }
|
|
1504
|
|
1505 if (fm->fmark.fnum != 0)
|
|
1506 vim_free(name);
|
|
1507 }
|
|
1508
|
|
1509 /*
|
|
1510 * Return TRUE if "name" is on removable media (depending on 'viminfo').
|
|
1511 */
|
|
1512 int
|
|
1513 removable(name)
|
|
1514 char_u *name;
|
|
1515 {
|
|
1516 char_u *p;
|
|
1517 char_u part[51];
|
|
1518 int retval = FALSE;
|
307
|
1519 size_t n;
|
7
|
1520
|
|
1521 name = home_replace_save(NULL, name);
|
|
1522 if (name != NULL)
|
|
1523 {
|
|
1524 for (p = p_viminfo; *p; )
|
|
1525 {
|
|
1526 copy_option_part(&p, part, 51, ", ");
|
307
|
1527 if (part[0] == 'r')
|
7
|
1528 {
|
307
|
1529 n = STRLEN(part + 1);
|
|
1530 if (MB_STRNICMP(part + 1, name, n) == 0)
|
|
1531 {
|
|
1532 retval = TRUE;
|
|
1533 break;
|
|
1534 }
|
7
|
1535 }
|
|
1536 }
|
|
1537 vim_free(name);
|
|
1538 }
|
|
1539 return retval;
|
|
1540 }
|
|
1541
|
|
1542 static void write_one_mark __ARGS((FILE *fp_out, int c, pos_T *pos));
|
|
1543
|
|
1544 /*
|
|
1545 * Write all the named marks for all buffers.
|
|
1546 * Return the number of buffers for which marks have been written.
|
|
1547 */
|
|
1548 int
|
|
1549 write_viminfo_marks(fp_out)
|
|
1550 FILE *fp_out;
|
|
1551 {
|
|
1552 int count;
|
|
1553 buf_T *buf;
|
|
1554 int is_mark_set;
|
|
1555 int i;
|
|
1556 #ifdef FEAT_WINDOWS
|
|
1557 win_T *win;
|
671
|
1558 tabpage_T *tp;
|
7
|
1559
|
|
1560 /*
|
|
1561 * Set b_last_cursor for the all buffers that have a window.
|
|
1562 */
|
671
|
1563 FOR_ALL_TAB_WINDOWS(tp, win)
|
7
|
1564 set_last_cursor(win);
|
|
1565 #else
|
|
1566 set_last_cursor(curwin);
|
|
1567 #endif
|
|
1568
|
|
1569 fprintf(fp_out, _("\n# History of marks within files (newest to oldest):\n"));
|
|
1570 count = 0;
|
|
1571 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
1572 {
|
|
1573 /*
|
|
1574 * Only write something if buffer has been loaded and at least one
|
|
1575 * mark is set.
|
|
1576 */
|
|
1577 if (buf->b_marks_read)
|
|
1578 {
|
|
1579 if (buf->b_last_cursor.lnum != 0)
|
|
1580 is_mark_set = TRUE;
|
|
1581 else
|
|
1582 {
|
|
1583 is_mark_set = FALSE;
|
|
1584 for (i = 0; i < NMARKS; i++)
|
|
1585 if (buf->b_namedm[i].lnum != 0)
|
|
1586 {
|
|
1587 is_mark_set = TRUE;
|
|
1588 break;
|
|
1589 }
|
|
1590 }
|
|
1591 if (is_mark_set && buf->b_ffname != NULL
|
|
1592 && buf->b_ffname[0] != NUL && !removable(buf->b_ffname))
|
|
1593 {
|
|
1594 home_replace(NULL, buf->b_ffname, IObuff, IOSIZE, TRUE);
|
|
1595 fprintf(fp_out, "\n> ");
|
|
1596 viminfo_writestring(fp_out, IObuff);
|
|
1597 write_one_mark(fp_out, '"', &buf->b_last_cursor);
|
|
1598 write_one_mark(fp_out, '^', &buf->b_last_insert);
|
|
1599 write_one_mark(fp_out, '.', &buf->b_last_change);
|
|
1600 #ifdef FEAT_JUMPLIST
|
|
1601 /* changelist positions are stored oldest first */
|
|
1602 for (i = 0; i < buf->b_changelistlen; ++i)
|
|
1603 write_one_mark(fp_out, '+', &buf->b_changelist[i]);
|
|
1604 #endif
|
|
1605 for (i = 0; i < NMARKS; i++)
|
|
1606 write_one_mark(fp_out, 'a' + i, &buf->b_namedm[i]);
|
|
1607 count++;
|
|
1608 }
|
|
1609 }
|
|
1610 }
|
|
1611
|
|
1612 return count;
|
|
1613 }
|
|
1614
|
|
1615 static void
|
|
1616 write_one_mark(fp_out, c, pos)
|
|
1617 FILE *fp_out;
|
|
1618 int c;
|
|
1619 pos_T *pos;
|
|
1620 {
|
|
1621 if (pos->lnum != 0)
|
|
1622 fprintf(fp_out, "\t%c\t%ld\t%d\n", c, (long)pos->lnum, (int)pos->col);
|
|
1623 }
|
|
1624
|
|
1625 /*
|
|
1626 * Handle marks in the viminfo file:
|
|
1627 * fp_out == NULL read marks for current buffer only
|
|
1628 * fp_out != NULL copy marks for buffers not in buffer list
|
|
1629 */
|
|
1630 void
|
|
1631 copy_viminfo_marks(virp, fp_out, count, eof)
|
|
1632 vir_T *virp;
|
|
1633 FILE *fp_out;
|
|
1634 int count;
|
|
1635 int eof;
|
|
1636 {
|
|
1637 char_u *line = virp->vir_line;
|
|
1638 buf_T *buf;
|
|
1639 int num_marked_files;
|
|
1640 int load_marks;
|
|
1641 int copy_marks_out;
|
|
1642 char_u *str;
|
|
1643 int i;
|
|
1644 char_u *p;
|
|
1645 char_u *name_buf;
|
|
1646 pos_T pos;
|
|
1647
|
|
1648 if ((name_buf = alloc(LSIZE)) == NULL)
|
|
1649 return;
|
|
1650 *name_buf = NUL;
|
|
1651 num_marked_files = get_viminfo_parameter('\'');
|
|
1652 while (!eof && (count < num_marked_files || fp_out == NULL))
|
|
1653 {
|
|
1654 if (line[0] != '>')
|
|
1655 {
|
|
1656 if (line[0] != '\n' && line[0] != '\r' && line[0] != '#')
|
|
1657 {
|
|
1658 if (viminfo_error("E576: ", _("Missing '>'"), line))
|
|
1659 break; /* too many errors, return now */
|
|
1660 }
|
|
1661 eof = vim_fgets(line, LSIZE, virp->vir_fd);
|
|
1662 continue; /* Skip this dud line */
|
|
1663 }
|
|
1664
|
|
1665 /*
|
|
1666 * Handle long line and translate escaped characters.
|
|
1667 * Find file name, set str to start.
|
|
1668 * Ignore leading and trailing white space.
|
|
1669 */
|
|
1670 str = skipwhite(line + 1);
|
|
1671 str = viminfo_readstring(virp, (int)(str - virp->vir_line), FALSE);
|
|
1672 if (str == NULL)
|
|
1673 continue;
|
|
1674 p = str + STRLEN(str);
|
|
1675 while (p != str && (*p == NUL || vim_isspace(*p)))
|
|
1676 p--;
|
|
1677 if (*p)
|
|
1678 p++;
|
|
1679 *p = NUL;
|
|
1680
|
|
1681 /*
|
|
1682 * If fp_out == NULL, load marks for current buffer.
|
|
1683 * If fp_out != NULL, copy marks for buffers not in buflist.
|
|
1684 */
|
|
1685 load_marks = copy_marks_out = FALSE;
|
|
1686 if (fp_out == NULL)
|
|
1687 {
|
|
1688 if (curbuf->b_ffname != NULL)
|
|
1689 {
|
|
1690 if (*name_buf == NUL) /* only need to do this once */
|
|
1691 home_replace(NULL, curbuf->b_ffname, name_buf, LSIZE, TRUE);
|
|
1692 if (fnamecmp(str, name_buf) == 0)
|
|
1693 load_marks = TRUE;
|
|
1694 }
|
|
1695 }
|
|
1696 else /* fp_out != NULL */
|
|
1697 {
|
|
1698 /* This is slow if there are many buffers!! */
|
|
1699 for (buf = firstbuf; buf != NULL; buf = buf->b_next)
|
|
1700 if (buf->b_ffname != NULL)
|
|
1701 {
|
|
1702 home_replace(NULL, buf->b_ffname, name_buf, LSIZE, TRUE);
|
|
1703 if (fnamecmp(str, name_buf) == 0)
|
|
1704 break;
|
|
1705 }
|
|
1706
|
|
1707 /*
|
|
1708 * copy marks if the buffer has not been loaded
|
|
1709 */
|
|
1710 if (buf == NULL || !buf->b_marks_read)
|
|
1711 {
|
|
1712 copy_marks_out = TRUE;
|
|
1713 fputs("\n> ", fp_out);
|
|
1714 viminfo_writestring(fp_out, str);
|
|
1715 count++;
|
|
1716 }
|
|
1717 }
|
|
1718 vim_free(str);
|
|
1719
|
|
1720 #ifdef FEAT_VIRTUALEDIT
|
|
1721 pos.coladd = 0;
|
|
1722 #endif
|
|
1723 while (!(eof = viminfo_readline(virp)) && line[0] == TAB)
|
|
1724 {
|
|
1725 if (load_marks)
|
|
1726 {
|
|
1727 if (line[1] != NUL)
|
|
1728 {
|
|
1729 sscanf((char *)line + 2, "%ld %u", &pos.lnum, &pos.col);
|
|
1730 switch (line[1])
|
|
1731 {
|
|
1732 case '"': curbuf->b_last_cursor = pos; break;
|
|
1733 case '^': curbuf->b_last_insert = pos; break;
|
|
1734 case '.': curbuf->b_last_change = pos; break;
|
|
1735 case '+':
|
|
1736 #ifdef FEAT_JUMPLIST
|
|
1737 /* changelist positions are stored oldest
|
|
1738 * first */
|
|
1739 if (curbuf->b_changelistlen == JUMPLISTSIZE)
|
|
1740 /* list is full, remove oldest entry */
|
|
1741 mch_memmove(curbuf->b_changelist,
|
|
1742 curbuf->b_changelist + 1,
|
|
1743 sizeof(pos_T) * (JUMPLISTSIZE - 1));
|
|
1744 else
|
|
1745 ++curbuf->b_changelistlen;
|
|
1746 curbuf->b_changelist[
|
|
1747 curbuf->b_changelistlen - 1] = pos;
|
|
1748 #endif
|
|
1749 break;
|
|
1750 default: if ((i = line[1] - 'a') >= 0 && i < NMARKS)
|
|
1751 curbuf->b_namedm[i] = pos;
|
|
1752 }
|
|
1753 }
|
|
1754 }
|
|
1755 else if (copy_marks_out)
|
|
1756 fputs((char *)line, fp_out);
|
|
1757 }
|
|
1758 if (load_marks)
|
|
1759 {
|
|
1760 #ifdef FEAT_JUMPLIST
|
|
1761 win_T *wp;
|
|
1762
|
|
1763 FOR_ALL_WINDOWS(wp)
|
|
1764 {
|
|
1765 if (wp->w_buffer == curbuf)
|
|
1766 wp->w_changelistidx = curbuf->b_changelistlen;
|
|
1767 }
|
|
1768 #endif
|
|
1769 break;
|
|
1770 }
|
|
1771 }
|
|
1772 vim_free(name_buf);
|
|
1773 }
|
|
1774 #endif /* FEAT_VIMINFO */
|