Mercurial > vim
comparison src/diff.c @ 18777:3a68dc2a1bc1 v8.1.2378
patch 8.1.2378: using old C style comments
Commit: https://github.com/vim/vim/commit/5d18efecfd6c45d69f55268948a22cd0465bb955
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Dec 1 21:11:22 2019 +0100
patch 8.1.2378: using old C style comments
Problem: Using old C style comments.
Solution: Use // comments where appropriate.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 01 Dec 2019 21:15:03 +0100 |
parents | 788d76db02ac |
children | 435726a03481 |
comparison
equal
deleted
inserted
replaced
18776:90a6831d6cd7 | 18777:3a68dc2a1bc1 |
---|---|
22 #if defined(FEAT_DIFF) || defined(PROTO) | 22 #if defined(FEAT_DIFF) || defined(PROTO) |
23 | 23 |
24 static int diff_busy = FALSE; // using diff structs, don't change them | 24 static int diff_busy = FALSE; // using diff structs, don't change them |
25 static int diff_need_update = FALSE; // ex_diffupdate needs to be called | 25 static int diff_need_update = FALSE; // ex_diffupdate needs to be called |
26 | 26 |
27 /* flags obtained from the 'diffopt' option */ | 27 // flags obtained from the 'diffopt' option |
28 #define DIFF_FILLER 0x001 // display filler lines | 28 #define DIFF_FILLER 0x001 // display filler lines |
29 #define DIFF_IBLANK 0x002 // ignore empty lines | 29 #define DIFF_IBLANK 0x002 // ignore empty lines |
30 #define DIFF_ICASE 0x004 // ignore case | 30 #define DIFF_ICASE 0x004 // ignore case |
31 #define DIFF_IWHITE 0x008 // ignore change in white space | 31 #define DIFF_IWHITE 0x008 // ignore change in white space |
32 #define DIFF_IWHITEALL 0x010 // ignore all white space changes | 32 #define DIFF_IWHITEALL 0x010 // ignore all white space changes |
39 #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) | 39 #define ALL_WHITE_DIFF (DIFF_IWHITE | DIFF_IWHITEALL | DIFF_IWHITEEOL) |
40 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; | 40 static int diff_flags = DIFF_INTERNAL | DIFF_FILLER | DIFF_CLOSE_OFF; |
41 | 41 |
42 static long diff_algorithm = 0; | 42 static long diff_algorithm = 0; |
43 | 43 |
44 #define LBUFLEN 50 /* length of line in diff file */ | 44 #define LBUFLEN 50 // length of line in diff file |
45 | 45 |
46 static int diff_a_works = MAYBE; /* TRUE when "diff -a" works, FALSE when it | 46 static int diff_a_works = MAYBE; // TRUE when "diff -a" works, FALSE when it |
47 doesn't work, MAYBE when not checked yet */ | 47 // doesn't work, MAYBE when not checked yet |
48 #if defined(MSWIN) | 48 #if defined(MSWIN) |
49 static int diff_bin_works = MAYBE; /* TRUE when "diff --binary" works, FALSE | 49 static int diff_bin_works = MAYBE; // TRUE when "diff --binary" works, FALSE |
50 when it doesn't work, MAYBE when not | 50 // when it doesn't work, MAYBE when not |
51 checked yet */ | 51 // checked yet |
52 #endif | 52 #endif |
53 | 53 |
54 // used for diff input | 54 // used for diff input |
55 typedef struct { | 55 typedef struct { |
56 char_u *din_fname; // used for external diff | 56 char_u *din_fname; // used for external diff |
122 win_T *wp; | 122 win_T *wp; |
123 int i; | 123 int i; |
124 | 124 |
125 if (!win->w_p_diff) | 125 if (!win->w_p_diff) |
126 { | 126 { |
127 /* When there is no window showing a diff for this buffer, remove | 127 // When there is no window showing a diff for this buffer, remove |
128 * it from the diffs. */ | 128 // it from the diffs. |
129 FOR_ALL_WINDOWS(wp) | 129 FOR_ALL_WINDOWS(wp) |
130 if (wp->w_buffer == win->w_buffer && wp->w_p_diff) | 130 if (wp->w_buffer == win->w_buffer && wp->w_p_diff) |
131 break; | 131 break; |
132 if (wp == NULL) | 132 if (wp == NULL) |
133 { | 133 { |
156 diff_buf_add(buf_T *buf) | 156 diff_buf_add(buf_T *buf) |
157 { | 157 { |
158 int i; | 158 int i; |
159 | 159 |
160 if (diff_buf_idx(buf) != DB_COUNT) | 160 if (diff_buf_idx(buf) != DB_COUNT) |
161 return; /* It's already there. */ | 161 return; // It's already there. |
162 | 162 |
163 for (i = 0; i < DB_COUNT; ++i) | 163 for (i = 0; i < DB_COUNT; ++i) |
164 if (curtab->tp_diffbuf[i] == NULL) | 164 if (curtab->tp_diffbuf[i] == NULL) |
165 { | 165 { |
166 curtab->tp_diffbuf[i] = buf; | 166 curtab->tp_diffbuf[i] = buf; |
252 long amount_after) | 252 long amount_after) |
253 { | 253 { |
254 int idx; | 254 int idx; |
255 tabpage_T *tp; | 255 tabpage_T *tp; |
256 | 256 |
257 /* Handle all tab pages that use the current buffer in a diff. */ | 257 // Handle all tab pages that use the current buffer in a diff. |
258 FOR_ALL_TABPAGES(tp) | 258 FOR_ALL_TABPAGES(tp) |
259 { | 259 { |
260 idx = diff_buf_idx_tp(curbuf, tp); | 260 idx = diff_buf_idx_tp(curbuf, tp); |
261 if (idx != DB_COUNT) | 261 if (idx != DB_COUNT) |
262 diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); | 262 diff_mark_adjust_tp(tp, idx, line1, line2, amount, amount_after); |
284 diff_T *dnext; | 284 diff_T *dnext; |
285 int i; | 285 int i; |
286 int inserted, deleted; | 286 int inserted, deleted; |
287 int n, off; | 287 int n, off; |
288 linenr_T last; | 288 linenr_T last; |
289 linenr_T lnum_deleted = line1; /* lnum of remaining deletion */ | 289 linenr_T lnum_deleted = line1; // lnum of remaining deletion |
290 int check_unchanged; | 290 int check_unchanged; |
291 | 291 |
292 if (diff_internal()) | 292 if (diff_internal()) |
293 { | 293 { |
294 // Will update diffs before redrawing. Set _invalid to update the | 294 // Will update diffs before redrawing. Set _invalid to update the |
299 tp->tp_diff_update = TRUE; | 299 tp->tp_diff_update = TRUE; |
300 } | 300 } |
301 | 301 |
302 if (line2 == MAXLNUM) | 302 if (line2 == MAXLNUM) |
303 { | 303 { |
304 /* mark_adjust(99, MAXLNUM, 9, 0): insert lines */ | 304 // mark_adjust(99, MAXLNUM, 9, 0): insert lines |
305 inserted = amount; | 305 inserted = amount; |
306 deleted = 0; | 306 deleted = 0; |
307 } | 307 } |
308 else if (amount_after > 0) | 308 else if (amount_after > 0) |
309 { | 309 { |
310 /* mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines*/ | 310 // mark_adjust(99, 98, MAXLNUM, 9): a change that inserts lines |
311 inserted = amount_after; | 311 inserted = amount_after; |
312 deleted = 0; | 312 deleted = 0; |
313 } | 313 } |
314 else | 314 else |
315 { | 315 { |
316 /* mark_adjust(98, 99, MAXLNUM, -2): delete lines */ | 316 // mark_adjust(98, 99, MAXLNUM, -2): delete lines |
317 inserted = 0; | 317 inserted = 0; |
318 deleted = -amount_after; | 318 deleted = -amount_after; |
319 } | 319 } |
320 | 320 |
321 dprev = NULL; | 321 dprev = NULL; |
322 dp = tp->tp_first_diff; | 322 dp = tp->tp_first_diff; |
323 for (;;) | 323 for (;;) |
324 { | 324 { |
325 /* If the change is after the previous diff block and before the next | 325 // If the change is after the previous diff block and before the next |
326 * diff block, thus not touching an existing change, create a new diff | 326 // diff block, thus not touching an existing change, create a new diff |
327 * block. Don't do this when ex_diffgetput() is busy. */ | 327 // block. Don't do this when ex_diffgetput() is busy. |
328 if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 | 328 if ((dp == NULL || dp->df_lnum[idx] - 1 > line2 |
329 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) | 329 || (line2 == MAXLNUM && dp->df_lnum[idx] > line1)) |
330 && (dprev == NULL | 330 && (dprev == NULL |
331 || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) | 331 || dprev->df_lnum[idx] + dprev->df_count[idx] < line1) |
332 && !diff_busy) | 332 && !diff_busy) |
348 - (dprev->df_lnum[idx] + dprev->df_count[idx]); | 348 - (dprev->df_lnum[idx] + dprev->df_count[idx]); |
349 dnext->df_count[i] = deleted; | 349 dnext->df_count[i] = deleted; |
350 } | 350 } |
351 } | 351 } |
352 | 352 |
353 /* if at end of the list, quit */ | 353 // if at end of the list, quit |
354 if (dp == NULL) | 354 if (dp == NULL) |
355 break; | 355 break; |
356 | 356 |
357 /* | 357 /* |
358 * Check for these situations: | 358 * Check for these situations: |
363 * 2 3 4 5 | 363 * 2 3 4 5 |
364 * line2 2 3 4 5 | 364 * line2 2 3 4 5 |
365 * 3 5 6 | 365 * 3 5 6 |
366 * 3 5 6 | 366 * 3 5 6 |
367 */ | 367 */ |
368 /* compute last line of this change */ | 368 // compute last line of this change |
369 last = dp->df_lnum[idx] + dp->df_count[idx] - 1; | 369 last = dp->df_lnum[idx] + dp->df_count[idx] - 1; |
370 | 370 |
371 /* 1. change completely above line1: nothing to do */ | 371 // 1. change completely above line1: nothing to do |
372 if (last >= line1 - 1) | 372 if (last >= line1 - 1) |
373 { | 373 { |
374 /* 6. change below line2: only adjust for amount_after; also when | 374 // 6. change below line2: only adjust for amount_after; also when |
375 * "deleted" became zero when deleted all lines between two diffs */ | 375 // "deleted" became zero when deleted all lines between two diffs |
376 if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) | 376 if (dp->df_lnum[idx] - (deleted + inserted != 0) > line2) |
377 { | 377 { |
378 if (amount_after == 0) | 378 if (amount_after == 0) |
379 break; /* nothing left to change */ | 379 break; // nothing left to change |
380 dp->df_lnum[idx] += amount_after; | 380 dp->df_lnum[idx] += amount_after; |
381 } | 381 } |
382 else | 382 else |
383 { | 383 { |
384 check_unchanged = FALSE; | 384 check_unchanged = FALSE; |
385 | 385 |
386 /* 2. 3. 4. 5.: inserted/deleted lines touching this diff. */ | 386 // 2. 3. 4. 5.: inserted/deleted lines touching this diff. |
387 if (deleted > 0) | 387 if (deleted > 0) |
388 { | 388 { |
389 if (dp->df_lnum[idx] >= line1) | 389 if (dp->df_lnum[idx] >= line1) |
390 { | 390 { |
391 off = dp->df_lnum[idx] - lnum_deleted; | 391 off = dp->df_lnum[idx] - lnum_deleted; |
392 if (last <= line2) | 392 if (last <= line2) |
393 { | 393 { |
394 /* 4. delete all lines of diff */ | 394 // 4. delete all lines of diff |
395 if (dp->df_next != NULL | 395 if (dp->df_next != NULL |
396 && dp->df_next->df_lnum[idx] - 1 <= line2) | 396 && dp->df_next->df_lnum[idx] - 1 <= line2) |
397 { | 397 { |
398 /* delete continues in next diff, only do | 398 // delete continues in next diff, only do |
399 * lines until that one */ | 399 // lines until that one |
400 n = dp->df_next->df_lnum[idx] - lnum_deleted; | 400 n = dp->df_next->df_lnum[idx] - lnum_deleted; |
401 deleted -= n; | 401 deleted -= n; |
402 n -= dp->df_count[idx]; | 402 n -= dp->df_count[idx]; |
403 lnum_deleted = dp->df_next->df_lnum[idx]; | 403 lnum_deleted = dp->df_next->df_lnum[idx]; |
404 } | 404 } |
406 n = deleted - dp->df_count[idx]; | 406 n = deleted - dp->df_count[idx]; |
407 dp->df_count[idx] = 0; | 407 dp->df_count[idx] = 0; |
408 } | 408 } |
409 else | 409 else |
410 { | 410 { |
411 /* 5. delete lines at or just before top of diff */ | 411 // 5. delete lines at or just before top of diff |
412 n = off; | 412 n = off; |
413 dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; | 413 dp->df_count[idx] -= line2 - dp->df_lnum[idx] + 1; |
414 check_unchanged = TRUE; | 414 check_unchanged = TRUE; |
415 } | 415 } |
416 dp->df_lnum[idx] = line1; | 416 dp->df_lnum[idx] = line1; |
418 else | 418 else |
419 { | 419 { |
420 off = 0; | 420 off = 0; |
421 if (last < line2) | 421 if (last < line2) |
422 { | 422 { |
423 /* 2. delete at end of diff */ | 423 // 2. delete at end of diff |
424 dp->df_count[idx] -= last - lnum_deleted + 1; | 424 dp->df_count[idx] -= last - lnum_deleted + 1; |
425 if (dp->df_next != NULL | 425 if (dp->df_next != NULL |
426 && dp->df_next->df_lnum[idx] - 1 <= line2) | 426 && dp->df_next->df_lnum[idx] - 1 <= line2) |
427 { | 427 { |
428 /* delete continues in next diff, only do | 428 // delete continues in next diff, only do |
429 * lines until that one */ | 429 // lines until that one |
430 n = dp->df_next->df_lnum[idx] - 1 - last; | 430 n = dp->df_next->df_lnum[idx] - 1 - last; |
431 deleted -= dp->df_next->df_lnum[idx] | 431 deleted -= dp->df_next->df_lnum[idx] |
432 - lnum_deleted; | 432 - lnum_deleted; |
433 lnum_deleted = dp->df_next->df_lnum[idx]; | 433 lnum_deleted = dp->df_next->df_lnum[idx]; |
434 } | 434 } |
436 n = line2 - last; | 436 n = line2 - last; |
437 check_unchanged = TRUE; | 437 check_unchanged = TRUE; |
438 } | 438 } |
439 else | 439 else |
440 { | 440 { |
441 /* 3. delete lines inside the diff */ | 441 // 3. delete lines inside the diff |
442 n = 0; | 442 n = 0; |
443 dp->df_count[idx] -= deleted; | 443 dp->df_count[idx] -= deleted; |
444 } | 444 } |
445 } | 445 } |
446 | 446 |
453 } | 453 } |
454 else | 454 else |
455 { | 455 { |
456 if (dp->df_lnum[idx] <= line1) | 456 if (dp->df_lnum[idx] <= line1) |
457 { | 457 { |
458 /* inserted lines somewhere in this diff */ | 458 // inserted lines somewhere in this diff |
459 dp->df_count[idx] += inserted; | 459 dp->df_count[idx] += inserted; |
460 check_unchanged = TRUE; | 460 check_unchanged = TRUE; |
461 } | 461 } |
462 else | 462 else |
463 /* inserted lines somewhere above this diff */ | 463 // inserted lines somewhere above this diff |
464 dp->df_lnum[idx] += inserted; | 464 dp->df_lnum[idx] += inserted; |
465 } | 465 } |
466 | 466 |
467 if (check_unchanged) | 467 if (check_unchanged) |
468 /* Check if inserted lines are equal, may reduce the | 468 // Check if inserted lines are equal, may reduce the |
469 * size of the diff. TODO: also check for equal lines | 469 // size of the diff. TODO: also check for equal lines |
470 * in the middle and perhaps split the block. */ | 470 // in the middle and perhaps split the block. |
471 diff_check_unchanged(tp, dp); | 471 diff_check_unchanged(tp, dp); |
472 } | 472 } |
473 } | 473 } |
474 | 474 |
475 /* check if this block touches the previous one, may merge them. */ | 475 // check if this block touches the previous one, may merge them. |
476 if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] | 476 if (dprev != NULL && dprev->df_lnum[idx] + dprev->df_count[idx] |
477 == dp->df_lnum[idx]) | 477 == dp->df_lnum[idx]) |
478 { | 478 { |
479 for (i = 0; i < DB_COUNT; ++i) | 479 for (i = 0; i < DB_COUNT; ++i) |
480 if (tp->tp_diffbuf[i] != NULL) | 480 if (tp->tp_diffbuf[i] != NULL) |
483 vim_free(dp); | 483 vim_free(dp); |
484 dp = dprev->df_next; | 484 dp = dprev->df_next; |
485 } | 485 } |
486 else | 486 else |
487 { | 487 { |
488 /* Advance to next entry. */ | 488 // Advance to next entry. |
489 dprev = dp; | 489 dprev = dp; |
490 dp = dp->df_next; | 490 dp = dp->df_next; |
491 } | 491 } |
492 } | 492 } |
493 | 493 |
494 dprev = NULL; | 494 dprev = NULL; |
495 dp = tp->tp_first_diff; | 495 dp = tp->tp_first_diff; |
496 while (dp != NULL) | 496 while (dp != NULL) |
497 { | 497 { |
498 /* All counts are zero, remove this entry. */ | 498 // All counts are zero, remove this entry. |
499 for (i = 0; i < DB_COUNT; ++i) | 499 for (i = 0; i < DB_COUNT; ++i) |
500 if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) | 500 if (tp->tp_diffbuf[i] != NULL && dp->df_count[i] != 0) |
501 break; | 501 break; |
502 if (i == DB_COUNT) | 502 if (i == DB_COUNT) |
503 { | 503 { |
509 else | 509 else |
510 dprev->df_next = dnext; | 510 dprev->df_next = dnext; |
511 } | 511 } |
512 else | 512 else |
513 { | 513 { |
514 /* Advance to next entry. */ | 514 // Advance to next entry. |
515 dprev = dp; | 515 dprev = dp; |
516 dp = dp->df_next; | 516 dp = dp->df_next; |
517 } | 517 } |
518 | 518 |
519 } | 519 } |
521 if (tp == curtab) | 521 if (tp == curtab) |
522 { | 522 { |
523 // Don't redraw right away, this updates the diffs, which can be slow. | 523 // Don't redraw right away, this updates the diffs, which can be slow. |
524 need_diff_redraw = TRUE; | 524 need_diff_redraw = TRUE; |
525 | 525 |
526 /* Need to recompute the scroll binding, may remove or add filler | 526 // Need to recompute the scroll binding, may remove or add filler |
527 * lines (e.g., when adding lines above w_topline). But it's slow when | 527 // lines (e.g., when adding lines above w_topline). But it's slow when |
528 * making many changes, postpone until redrawing. */ | 528 // making many changes, postpone until redrawing. |
529 diff_need_scrollbind = TRUE; | 529 diff_need_scrollbind = TRUE; |
530 } | 530 } |
531 } | 531 } |
532 | 532 |
533 /* | 533 /* |
563 int i_new; | 563 int i_new; |
564 int off_org, off_new; | 564 int off_org, off_new; |
565 char_u *line_org; | 565 char_u *line_org; |
566 int dir = FORWARD; | 566 int dir = FORWARD; |
567 | 567 |
568 /* Find the first buffers, use it as the original, compare the other | 568 // Find the first buffers, use it as the original, compare the other |
569 * buffer lines against this one. */ | 569 // buffer lines against this one. |
570 for (i_org = 0; i_org < DB_COUNT; ++i_org) | 570 for (i_org = 0; i_org < DB_COUNT; ++i_org) |
571 if (tp->tp_diffbuf[i_org] != NULL) | 571 if (tp->tp_diffbuf[i_org] != NULL) |
572 break; | 572 break; |
573 if (i_org == DB_COUNT) /* safety check */ | 573 if (i_org == DB_COUNT) // safety check |
574 return; | 574 return; |
575 | 575 |
576 if (diff_check_sanity(tp, dp) == FAIL) | 576 if (diff_check_sanity(tp, dp) == FAIL) |
577 return; | 577 return; |
578 | 578 |
579 /* First check lines at the top, then at the bottom. */ | 579 // First check lines at the top, then at the bottom. |
580 off_org = 0; | 580 off_org = 0; |
581 off_new = 0; | 581 off_new = 0; |
582 for (;;) | 582 for (;;) |
583 { | 583 { |
584 /* Repeat until a line is found which is different or the number of | 584 // Repeat until a line is found which is different or the number of |
585 * lines has become zero. */ | 585 // lines has become zero. |
586 while (dp->df_count[i_org] > 0) | 586 while (dp->df_count[i_org] > 0) |
587 { | 587 { |
588 /* Copy the line, the next ml_get() will invalidate it. */ | 588 // Copy the line, the next ml_get() will invalidate it. |
589 if (dir == BACKWARD) | 589 if (dir == BACKWARD) |
590 off_org = dp->df_count[i_org] - 1; | 590 off_org = dp->df_count[i_org] - 1; |
591 line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], | 591 line_org = vim_strsave(ml_get_buf(tp->tp_diffbuf[i_org], |
592 dp->df_lnum[i_org] + off_org, FALSE)); | 592 dp->df_lnum[i_org] + off_org, FALSE)); |
593 if (line_org == NULL) | 593 if (line_org == NULL) |
596 { | 596 { |
597 if (tp->tp_diffbuf[i_new] == NULL) | 597 if (tp->tp_diffbuf[i_new] == NULL) |
598 continue; | 598 continue; |
599 if (dir == BACKWARD) | 599 if (dir == BACKWARD) |
600 off_new = dp->df_count[i_new] - 1; | 600 off_new = dp->df_count[i_new] - 1; |
601 /* if other buffer doesn't have this line, it was inserted */ | 601 // if other buffer doesn't have this line, it was inserted |
602 if (off_new < 0 || off_new >= dp->df_count[i_new]) | 602 if (off_new < 0 || off_new >= dp->df_count[i_new]) |
603 break; | 603 break; |
604 if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], | 604 if (diff_cmp(line_org, ml_get_buf(tp->tp_diffbuf[i_new], |
605 dp->df_lnum[i_new] + off_new, FALSE)) != 0) | 605 dp->df_lnum[i_new] + off_new, FALSE)) != 0) |
606 break; | 606 break; |
607 } | 607 } |
608 vim_free(line_org); | 608 vim_free(line_org); |
609 | 609 |
610 /* Stop when a line isn't equal in all diff buffers. */ | 610 // Stop when a line isn't equal in all diff buffers. |
611 if (i_new != DB_COUNT) | 611 if (i_new != DB_COUNT) |
612 break; | 612 break; |
613 | 613 |
614 /* Line matched in all buffers, remove it from the diff. */ | 614 // Line matched in all buffers, remove it from the diff. |
615 for (i_new = i_org; i_new < DB_COUNT; ++i_new) | 615 for (i_new = i_org; i_new < DB_COUNT; ++i_new) |
616 if (tp->tp_diffbuf[i_new] != NULL) | 616 if (tp->tp_diffbuf[i_new] != NULL) |
617 { | 617 { |
618 if (dir == FORWARD) | 618 if (dir == FORWARD) |
619 ++dp->df_lnum[i_new]; | 619 ++dp->df_lnum[i_new]; |
660 redraw_win_later(wp, SOME_VALID); | 660 redraw_win_later(wp, SOME_VALID); |
661 #ifdef FEAT_FOLDING | 661 #ifdef FEAT_FOLDING |
662 if (dofold && foldmethodIsDiff(wp)) | 662 if (dofold && foldmethodIsDiff(wp)) |
663 foldUpdateAll(wp); | 663 foldUpdateAll(wp); |
664 #endif | 664 #endif |
665 /* A change may have made filler lines invalid, need to take care | 665 // A change may have made filler lines invalid, need to take care |
666 * of that for other windows. */ | 666 // of that for other windows. |
667 n = diff_check(wp, wp->w_topline); | 667 n = diff_check(wp, wp->w_topline); |
668 if ((wp != curwin && wp->w_topfill > 0) || n > 0) | 668 if ((wp != curwin && wp->w_topfill > 0) || n > 0) |
669 { | 669 { |
670 if (wp->w_topfill > n) | 670 if (wp->w_topfill > n) |
671 wp->w_topfill = (n < 0 ? 0 : n); | 671 wp->w_topfill = (n < 0 ? 0 : n); |
1001 { | 1001 { |
1002 char_u linebuf[LBUFLEN]; | 1002 char_u linebuf[LBUFLEN]; |
1003 | 1003 |
1004 for (;;) | 1004 for (;;) |
1005 { | 1005 { |
1006 /* There must be a line that contains "1c1". */ | 1006 // There must be a line that contains "1c1". |
1007 if (vim_fgets(linebuf, LBUFLEN, fd)) | 1007 if (vim_fgets(linebuf, LBUFLEN, fd)) |
1008 break; | 1008 break; |
1009 if (STRNCMP(linebuf, "1c1", 3) == 0) | 1009 if (STRNCMP(linebuf, "1c1", 3) == 0) |
1010 ok = TRUE; | 1010 ok = TRUE; |
1011 } | 1011 } |
1016 } | 1016 } |
1017 mch_remove(diffio->dio_orig.din_fname); | 1017 mch_remove(diffio->dio_orig.din_fname); |
1018 } | 1018 } |
1019 | 1019 |
1020 #ifdef FEAT_EVAL | 1020 #ifdef FEAT_EVAL |
1021 /* When using 'diffexpr' break here. */ | 1021 // When using 'diffexpr' break here. |
1022 if (*p_dex != NUL) | 1022 if (*p_dex != NUL) |
1023 break; | 1023 break; |
1024 #endif | 1024 #endif |
1025 | 1025 |
1026 #if defined(MSWIN) | 1026 #if defined(MSWIN) |
1027 /* If the "-a" argument works, also check if "--binary" works. */ | 1027 // If the "-a" argument works, also check if "--binary" works. |
1028 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) | 1028 if (ok && diff_a_works == MAYBE && diff_bin_works == MAYBE) |
1029 { | 1029 { |
1030 diff_a_works = TRUE; | 1030 diff_a_works = TRUE; |
1031 diff_bin_works = TRUE; | 1031 diff_bin_works = TRUE; |
1032 continue; | 1032 continue; |
1033 } | 1033 } |
1034 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) | 1034 if (!ok && diff_a_works == TRUE && diff_bin_works == TRUE) |
1035 { | 1035 { |
1036 /* Tried --binary, but it failed. "-a" works though. */ | 1036 // Tried --binary, but it failed. "-a" works though. |
1037 diff_bin_works = FALSE; | 1037 diff_bin_works = FALSE; |
1038 ok = TRUE; | 1038 ok = TRUE; |
1039 } | 1039 } |
1040 #endif | 1040 #endif |
1041 | 1041 |
1042 /* If we checked if "-a" works already, break here. */ | 1042 // If we checked if "-a" works already, break here. |
1043 if (diff_a_works != MAYBE) | 1043 if (diff_a_works != MAYBE) |
1044 break; | 1044 break; |
1045 diff_a_works = ok; | 1045 diff_a_works = ok; |
1046 | 1046 |
1047 /* If "-a" works break here, otherwise retry without "-a". */ | 1047 // If "-a" works break here, otherwise retry without "-a". |
1048 if (ok) | 1048 if (ok) |
1049 break; | 1049 break; |
1050 } | 1050 } |
1051 if (!ok) | 1051 if (!ok) |
1052 { | 1052 { |
1170 * could have been produced by autocommands, e.g. the netrw plugin). | 1170 * could have been produced by autocommands, e.g. the netrw plugin). |
1171 */ | 1171 */ |
1172 void | 1172 void |
1173 ex_diffpatch(exarg_T *eap) | 1173 ex_diffpatch(exarg_T *eap) |
1174 { | 1174 { |
1175 char_u *tmp_orig; /* name of original temp file */ | 1175 char_u *tmp_orig; // name of original temp file |
1176 char_u *tmp_new; /* name of patched temp file */ | 1176 char_u *tmp_new; // name of patched temp file |
1177 char_u *buf = NULL; | 1177 char_u *buf = NULL; |
1178 size_t buflen; | 1178 size_t buflen; |
1179 win_T *old_curwin = curwin; | 1179 win_T *old_curwin = curwin; |
1180 char_u *newname = NULL; /* name of patched file buffer */ | 1180 char_u *newname = NULL; // name of patched file buffer |
1181 #ifdef UNIX | 1181 #ifdef UNIX |
1182 char_u dirbuf[MAXPATHL]; | 1182 char_u dirbuf[MAXPATHL]; |
1183 char_u *fullname = NULL; | 1183 char_u *fullname = NULL; |
1184 #endif | 1184 #endif |
1185 #ifdef FEAT_BROWSE | 1185 #ifdef FEAT_BROWSE |
1194 { | 1194 { |
1195 browseFile = do_browse(0, (char_u *)_("Patch file"), | 1195 browseFile = do_browse(0, (char_u *)_("Patch file"), |
1196 eap->arg, NULL, NULL, | 1196 eap->arg, NULL, NULL, |
1197 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); | 1197 (char_u *)_(BROWSE_FILTER_ALL_FILES), NULL); |
1198 if (browseFile == NULL) | 1198 if (browseFile == NULL) |
1199 return; /* operation cancelled */ | 1199 return; // operation cancelled |
1200 eap->arg = browseFile; | 1200 eap->arg = browseFile; |
1201 cmdmod.browse = FALSE; /* don't let do_ecmd() browse again */ | 1201 cmdmod.browse = FALSE; // don't let do_ecmd() browse again |
1202 } | 1202 } |
1203 #endif | 1203 #endif |
1204 | 1204 |
1205 /* We need two temp file names. */ | 1205 // We need two temp file names. |
1206 tmp_orig = vim_tempname('o', FALSE); | 1206 tmp_orig = vim_tempname('o', FALSE); |
1207 tmp_new = vim_tempname('n', FALSE); | 1207 tmp_new = vim_tempname('n', FALSE); |
1208 if (tmp_orig == NULL || tmp_new == NULL) | 1208 if (tmp_orig == NULL || tmp_new == NULL) |
1209 goto theend; | 1209 goto theend; |
1210 | 1210 |
1211 /* Write the current buffer to "tmp_orig". */ | 1211 // Write the current buffer to "tmp_orig". |
1212 if (buf_write(curbuf, tmp_orig, NULL, | 1212 if (buf_write(curbuf, tmp_orig, NULL, |
1213 (linenr_T)1, curbuf->b_ml.ml_line_count, | 1213 (linenr_T)1, curbuf->b_ml.ml_line_count, |
1214 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) | 1214 NULL, FALSE, FALSE, FALSE, TRUE) == FAIL) |
1215 goto theend; | 1215 goto theend; |
1216 | 1216 |
1217 #ifdef UNIX | 1217 #ifdef UNIX |
1218 /* Get the absolute path of the patchfile, changing directory below. */ | 1218 // Get the absolute path of the patchfile, changing directory below. |
1219 fullname = FullName_save(eap->arg, FALSE); | 1219 fullname = FullName_save(eap->arg, FALSE); |
1220 #endif | 1220 #endif |
1221 esc_name = vim_strsave_shellescape( | 1221 esc_name = vim_strsave_shellescape( |
1222 # ifdef UNIX | 1222 # ifdef UNIX |
1223 fullname != NULL ? fullname : | 1223 fullname != NULL ? fullname : |
1229 buf = alloc(buflen); | 1229 buf = alloc(buflen); |
1230 if (buf == NULL) | 1230 if (buf == NULL) |
1231 goto theend; | 1231 goto theend; |
1232 | 1232 |
1233 #ifdef UNIX | 1233 #ifdef UNIX |
1234 /* Temporarily chdir to /tmp, to avoid patching files in the current | 1234 // Temporarily chdir to /tmp, to avoid patching files in the current |
1235 * directory when the patch file contains more than one patch. When we | 1235 // directory when the patch file contains more than one patch. When we |
1236 * have our own temp dir use that instead, it will be cleaned up when we | 1236 // have our own temp dir use that instead, it will be cleaned up when we |
1237 * exit (any .rej files created). Don't change directory if we can't | 1237 // exit (any .rej files created). Don't change directory if we can't |
1238 * return to the current. */ | 1238 // return to the current. |
1239 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) | 1239 if (mch_dirname(dirbuf, MAXPATHL) != OK || mch_chdir((char *)dirbuf) != 0) |
1240 dirbuf[0] = NUL; | 1240 dirbuf[0] = NUL; |
1241 else | 1241 else |
1242 { | 1242 { |
1243 # ifdef TEMPDIRNAMES | 1243 # ifdef TEMPDIRNAMES |
1250 } | 1250 } |
1251 #endif | 1251 #endif |
1252 | 1252 |
1253 #ifdef FEAT_EVAL | 1253 #ifdef FEAT_EVAL |
1254 if (*p_pex != NUL) | 1254 if (*p_pex != NUL) |
1255 /* Use 'patchexpr' to generate the new file. */ | 1255 // Use 'patchexpr' to generate the new file. |
1256 eval_patch(tmp_orig, | 1256 eval_patch(tmp_orig, |
1257 # ifdef UNIX | 1257 # ifdef UNIX |
1258 fullname != NULL ? fullname : | 1258 fullname != NULL ? fullname : |
1259 # endif | 1259 # endif |
1260 eap->arg, tmp_new); | 1260 eap->arg, tmp_new); |
1261 else | 1261 else |
1262 #endif | 1262 #endif |
1263 { | 1263 { |
1264 /* Build the patch command and execute it. Ignore errors. Switch to | 1264 // Build the patch command and execute it. Ignore errors. Switch to |
1265 * cooked mode to allow the user to respond to prompts. */ | 1265 // cooked mode to allow the user to respond to prompts. |
1266 vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", | 1266 vim_snprintf((char *)buf, buflen, "patch -o %s %s < %s", |
1267 tmp_new, tmp_orig, esc_name); | 1267 tmp_new, tmp_orig, esc_name); |
1268 block_autocmds(); /* Avoid ShellCmdPost stuff */ | 1268 block_autocmds(); // Avoid ShellCmdPost stuff |
1269 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); | 1269 (void)call_shell(buf, SHELL_FILTER | SHELL_COOKED); |
1270 unblock_autocmds(); | 1270 unblock_autocmds(); |
1271 } | 1271 } |
1272 | 1272 |
1273 #ifdef UNIX | 1273 #ifdef UNIX |
1277 emsg(_(e_prev_dir)); | 1277 emsg(_(e_prev_dir)); |
1278 shorten_fnames(TRUE); | 1278 shorten_fnames(TRUE); |
1279 } | 1279 } |
1280 #endif | 1280 #endif |
1281 | 1281 |
1282 /* patch probably has written over the screen */ | 1282 // patch probably has written over the screen |
1283 redraw_later(CLEAR); | 1283 redraw_later(CLEAR); |
1284 | 1284 |
1285 /* Delete any .orig or .rej file created. */ | 1285 // Delete any .orig or .rej file created. |
1286 STRCPY(buf, tmp_new); | 1286 STRCPY(buf, tmp_new); |
1287 STRCAT(buf, ".orig"); | 1287 STRCAT(buf, ".orig"); |
1288 mch_remove(buf); | 1288 mch_remove(buf); |
1289 STRCPY(buf, tmp_new); | 1289 STRCPY(buf, tmp_new); |
1290 STRCAT(buf, ".rej"); | 1290 STRCAT(buf, ".rej"); |
1291 mch_remove(buf); | 1291 mch_remove(buf); |
1292 | 1292 |
1293 /* Only continue if the output file was created. */ | 1293 // Only continue if the output file was created. |
1294 if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) | 1294 if (mch_stat((char *)tmp_new, &st) < 0 || st.st_size == 0) |
1295 emsg(_("E816: Cannot read patch output")); | 1295 emsg(_("E816: Cannot read patch output")); |
1296 else | 1296 else |
1297 { | 1297 { |
1298 if (curbuf->b_fname != NULL) | 1298 if (curbuf->b_fname != NULL) |
1304 } | 1304 } |
1305 | 1305 |
1306 #ifdef FEAT_GUI | 1306 #ifdef FEAT_GUI |
1307 need_mouse_correct = TRUE; | 1307 need_mouse_correct = TRUE; |
1308 #endif | 1308 #endif |
1309 /* don't use a new tab page, each tab page has its own diffs */ | 1309 // don't use a new tab page, each tab page has its own diffs |
1310 cmdmod.tab = 0; | 1310 cmdmod.tab = 0; |
1311 | 1311 |
1312 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) | 1312 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1313 { | 1313 { |
1314 /* Pretend it was a ":split fname" command */ | 1314 // Pretend it was a ":split fname" command |
1315 eap->cmdidx = CMD_split; | 1315 eap->cmdidx = CMD_split; |
1316 eap->arg = tmp_new; | 1316 eap->arg = tmp_new; |
1317 do_exedit(eap, old_curwin); | 1317 do_exedit(eap, old_curwin); |
1318 | 1318 |
1319 /* check that split worked and editing tmp_new */ | 1319 // check that split worked and editing tmp_new |
1320 if (curwin != old_curwin && win_valid(old_curwin)) | 1320 if (curwin != old_curwin && win_valid(old_curwin)) |
1321 { | 1321 { |
1322 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | 1322 // Set 'diff', 'scrollbind' on and 'wrap' off. |
1323 diff_win_options(curwin, TRUE); | 1323 diff_win_options(curwin, TRUE); |
1324 diff_win_options(old_curwin, TRUE); | 1324 diff_win_options(old_curwin, TRUE); |
1325 | 1325 |
1326 if (newname != NULL) | 1326 if (newname != NULL) |
1327 { | 1327 { |
1328 /* do a ":file filename.new" on the patched buffer */ | 1328 // do a ":file filename.new" on the patched buffer |
1329 eap->arg = newname; | 1329 eap->arg = newname; |
1330 ex_file(eap); | 1330 ex_file(eap); |
1331 | 1331 |
1332 /* Do filetype detection with the new name. */ | 1332 // Do filetype detection with the new name. |
1333 if (au_has_group((char_u *)"filetypedetect")) | 1333 if (au_has_group((char_u *)"filetypedetect")) |
1334 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); | 1334 do_cmdline_cmd((char_u *)":doau filetypedetect BufRead"); |
1335 } | 1335 } |
1336 } | 1336 } |
1337 } | 1337 } |
1367 | 1367 |
1368 set_bufref(&old_curbuf, curbuf); | 1368 set_bufref(&old_curbuf, curbuf); |
1369 #ifdef FEAT_GUI | 1369 #ifdef FEAT_GUI |
1370 need_mouse_correct = TRUE; | 1370 need_mouse_correct = TRUE; |
1371 #endif | 1371 #endif |
1372 /* Need to compute w_fraction when no redraw happened yet. */ | 1372 // Need to compute w_fraction when no redraw happened yet. |
1373 validate_cursor(); | 1373 validate_cursor(); |
1374 set_fraction(curwin); | 1374 set_fraction(curwin); |
1375 | 1375 |
1376 /* don't use a new tab page, each tab page has its own diffs */ | 1376 // don't use a new tab page, each tab page has its own diffs |
1377 cmdmod.tab = 0; | 1377 cmdmod.tab = 0; |
1378 | 1378 |
1379 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) | 1379 if (win_split(0, (diff_flags & DIFF_VERTICAL) ? WSP_VERT : 0) != FAIL) |
1380 { | 1380 { |
1381 /* Pretend it was a ":split fname" command */ | 1381 // Pretend it was a ":split fname" command |
1382 eap->cmdidx = CMD_split; | 1382 eap->cmdidx = CMD_split; |
1383 curwin->w_p_diff = TRUE; | 1383 curwin->w_p_diff = TRUE; |
1384 do_exedit(eap, old_curwin); | 1384 do_exedit(eap, old_curwin); |
1385 | 1385 |
1386 if (curwin != old_curwin) /* split must have worked */ | 1386 if (curwin != old_curwin) // split must have worked |
1387 { | 1387 { |
1388 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | 1388 // Set 'diff', 'scrollbind' on and 'wrap' off. |
1389 diff_win_options(curwin, TRUE); | 1389 diff_win_options(curwin, TRUE); |
1390 if (win_valid(old_curwin)) | 1390 if (win_valid(old_curwin)) |
1391 { | 1391 { |
1392 diff_win_options(old_curwin, TRUE); | 1392 diff_win_options(old_curwin, TRUE); |
1393 | 1393 |
1394 if (bufref_valid(&old_curbuf)) | 1394 if (bufref_valid(&old_curbuf)) |
1395 /* Move the cursor position to that of the old window. */ | 1395 // Move the cursor position to that of the old window. |
1396 curwin->w_cursor.lnum = diff_get_corresponding_line( | 1396 curwin->w_cursor.lnum = diff_get_corresponding_line( |
1397 old_curbuf.br_buf, old_curwin->w_cursor.lnum); | 1397 old_curbuf.br_buf, old_curwin->w_cursor.lnum); |
1398 } | 1398 } |
1399 /* Now that lines are folded scroll to show the cursor at the same | 1399 // Now that lines are folded scroll to show the cursor at the same |
1400 * relative position. */ | 1400 // relative position. |
1401 scroll_to_fraction(curwin, curwin->w_height); | 1401 scroll_to_fraction(curwin, curwin->w_height); |
1402 } | 1402 } |
1403 } | 1403 } |
1404 } | 1404 } |
1405 | 1405 |
1407 * Set options to show diffs for the current window. | 1407 * Set options to show diffs for the current window. |
1408 */ | 1408 */ |
1409 void | 1409 void |
1410 ex_diffthis(exarg_T *eap UNUSED) | 1410 ex_diffthis(exarg_T *eap UNUSED) |
1411 { | 1411 { |
1412 /* Set 'diff', 'scrollbind' on and 'wrap' off. */ | 1412 // Set 'diff', 'scrollbind' on and 'wrap' off. |
1413 diff_win_options(curwin, TRUE); | 1413 diff_win_options(curwin, TRUE); |
1414 } | 1414 } |
1415 | 1415 |
1416 static void | 1416 static void |
1417 set_diff_option(win_T *wp, int value) | 1417 set_diff_option(win_T *wp, int value) |
1431 * Set options in window "wp" for diff mode. | 1431 * Set options in window "wp" for diff mode. |
1432 */ | 1432 */ |
1433 void | 1433 void |
1434 diff_win_options( | 1434 diff_win_options( |
1435 win_T *wp, | 1435 win_T *wp, |
1436 int addbuf) /* Add buffer to diff. */ | 1436 int addbuf) // Add buffer to diff. |
1437 { | 1437 { |
1438 # ifdef FEAT_FOLDING | 1438 # ifdef FEAT_FOLDING |
1439 win_T *old_curwin = curwin; | 1439 win_T *old_curwin = curwin; |
1440 | 1440 |
1441 /* close the manually opened folds */ | 1441 // close the manually opened folds |
1442 curwin = wp; | 1442 curwin = wp; |
1443 newFoldLevel(); | 1443 newFoldLevel(); |
1444 curwin = old_curwin; | 1444 curwin = old_curwin; |
1445 # endif | 1445 # endif |
1446 | 1446 |
1447 /* Use 'scrollbind' and 'cursorbind' when available */ | 1447 // Use 'scrollbind' and 'cursorbind' when available |
1448 if (!wp->w_p_diff) | 1448 if (!wp->w_p_diff) |
1449 wp->w_p_scb_save = wp->w_p_scb; | 1449 wp->w_p_scb_save = wp->w_p_scb; |
1450 wp->w_p_scb = TRUE; | 1450 wp->w_p_scb = TRUE; |
1451 if (!wp->w_p_diff) | 1451 if (!wp->w_p_diff) |
1452 wp->w_p_crb_save = wp->w_p_crb; | 1452 wp->w_p_crb_save = wp->w_p_crb; |
1471 } | 1471 } |
1472 wp->w_p_fdc = diff_foldcolumn; | 1472 wp->w_p_fdc = diff_foldcolumn; |
1473 wp->w_p_fen = TRUE; | 1473 wp->w_p_fen = TRUE; |
1474 wp->w_p_fdl = 0; | 1474 wp->w_p_fdl = 0; |
1475 foldUpdateAll(wp); | 1475 foldUpdateAll(wp); |
1476 /* make sure topline is not halfway a fold */ | 1476 // make sure topline is not halfway a fold |
1477 changed_window_setting_win(wp); | 1477 changed_window_setting_win(wp); |
1478 # endif | 1478 # endif |
1479 if (vim_strchr(p_sbo, 'h') == NULL) | 1479 if (vim_strchr(p_sbo, 'h') == NULL) |
1480 do_cmdline_cmd((char_u *)"set sbo+=hor"); | 1480 do_cmdline_cmd((char_u *)"set sbo+=hor"); |
1481 /* Save the current values, to be restored in ex_diffoff(). */ | 1481 // Save the current values, to be restored in ex_diffoff(). |
1482 wp->w_p_diff_saved = TRUE; | 1482 wp->w_p_diff_saved = TRUE; |
1483 | 1483 |
1484 set_diff_option(wp, TRUE); | 1484 set_diff_option(wp, TRUE); |
1485 | 1485 |
1486 if (addbuf) | 1486 if (addbuf) |
1500 | 1500 |
1501 FOR_ALL_WINDOWS(wp) | 1501 FOR_ALL_WINDOWS(wp) |
1502 { | 1502 { |
1503 if (eap->forceit ? wp->w_p_diff : wp == curwin) | 1503 if (eap->forceit ? wp->w_p_diff : wp == curwin) |
1504 { | 1504 { |
1505 /* Set 'diff' off. If option values were saved in | 1505 // Set 'diff' off. If option values were saved in |
1506 * diff_win_options(), restore the ones whose settings seem to have | 1506 // diff_win_options(), restore the ones whose settings seem to have |
1507 * been left over from diff mode. */ | 1507 // been left over from diff mode. |
1508 set_diff_option(wp, FALSE); | 1508 set_diff_option(wp, FALSE); |
1509 | 1509 |
1510 if (wp->w_p_diff_saved) | 1510 if (wp->w_p_diff_saved) |
1511 { | 1511 { |
1512 | 1512 |
1524 if (wp->w_p_fdc == diff_foldcolumn) | 1524 if (wp->w_p_fdc == diff_foldcolumn) |
1525 wp->w_p_fdc = wp->w_p_fdc_save; | 1525 wp->w_p_fdc = wp->w_p_fdc_save; |
1526 if (wp->w_p_fdl == 0) | 1526 if (wp->w_p_fdl == 0) |
1527 wp->w_p_fdl = wp->w_p_fdl_save; | 1527 wp->w_p_fdl = wp->w_p_fdl_save; |
1528 | 1528 |
1529 /* Only restore 'foldenable' when 'foldmethod' is not | 1529 // Only restore 'foldenable' when 'foldmethod' is not |
1530 * "manual", otherwise we continue to show the diff folds. */ | 1530 // "manual", otherwise we continue to show the diff folds. |
1531 if (wp->w_p_fen) | 1531 if (wp->w_p_fen) |
1532 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE | 1532 wp->w_p_fen = foldmethodIsManual(wp) ? FALSE |
1533 : wp->w_p_fen_save; | 1533 : wp->w_p_fen_save; |
1534 | 1534 |
1535 foldUpdateAll(wp); | 1535 foldUpdateAll(wp); |
1536 #endif | 1536 #endif |
1537 } | 1537 } |
1538 /* remove filler lines */ | 1538 // remove filler lines |
1539 wp->w_topfill = 0; | 1539 wp->w_topfill = 0; |
1540 | 1540 |
1541 /* make sure topline is not halfway a fold and cursor is | 1541 // make sure topline is not halfway a fold and cursor is |
1542 * invalidated */ | 1542 // invalidated |
1543 changed_window_setting_win(wp); | 1543 changed_window_setting_win(wp); |
1544 | 1544 |
1545 /* Note: 'sbo' is not restored, it's a global option. */ | 1545 // Note: 'sbo' is not restored, it's a global option. |
1546 diff_buf_adjust(wp); | 1546 diff_buf_adjust(wp); |
1547 } | 1547 } |
1548 diffwin |= wp->w_p_diff; | 1548 diffwin |= wp->w_p_diff; |
1549 } | 1549 } |
1550 | 1550 |
1551 /* Also remove hidden buffers from the list. */ | 1551 // Also remove hidden buffers from the list. |
1552 if (eap->forceit) | 1552 if (eap->forceit) |
1553 diff_buf_clear(); | 1553 diff_buf_clear(); |
1554 | 1554 |
1555 if (!diffwin) | 1555 if (!diffwin) |
1556 { | 1556 { |
1558 curtab->tp_diff_invalid = FALSE; | 1558 curtab->tp_diff_invalid = FALSE; |
1559 curtab->tp_diff_update = FALSE; | 1559 curtab->tp_diff_update = FALSE; |
1560 diff_clear(curtab); | 1560 diff_clear(curtab); |
1561 } | 1561 } |
1562 | 1562 |
1563 /* Remove "hor" from from 'scrollopt' if there are no diff windows left. */ | 1563 // Remove "hor" from from 'scrollopt' if there are no diff windows left. |
1564 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) | 1564 if (!diffwin && vim_strchr(p_sbo, 'h') != NULL) |
1565 do_cmdline_cmd((char_u *)"set sbo-=hor"); | 1565 do_cmdline_cmd((char_u *)"set sbo-=hor"); |
1566 } | 1566 } |
1567 | 1567 |
1568 /* | 1568 /* |
1577 FILE *fd = NULL; | 1577 FILE *fd = NULL; |
1578 int line_idx = 0; | 1578 int line_idx = 0; |
1579 diff_T *dprev = NULL; | 1579 diff_T *dprev = NULL; |
1580 diff_T *dp = curtab->tp_first_diff; | 1580 diff_T *dp = curtab->tp_first_diff; |
1581 diff_T *dn, *dpl; | 1581 diff_T *dn, *dpl; |
1582 char_u linebuf[LBUFLEN]; /* only need to hold the diff line */ | 1582 char_u linebuf[LBUFLEN]; // only need to hold the diff line |
1583 char_u *line; | 1583 char_u *line; |
1584 long off; | 1584 long off; |
1585 int i; | 1585 int i; |
1586 linenr_T lnum_orig, lnum_new; | 1586 linenr_T lnum_orig, lnum_new; |
1587 long count_orig, count_new; | 1587 long count_orig, count_new; |
1588 int notset = TRUE; /* block "*dp" not set yet */ | 1588 int notset = TRUE; // block "*dp" not set yet |
1589 enum { | 1589 enum { |
1590 DIFF_ED, | 1590 DIFF_ED, |
1591 DIFF_UNIFIED, | 1591 DIFF_UNIFIED, |
1592 DIFF_NONE | 1592 DIFF_NONE |
1593 } diffstyle = DIFF_NONE; | 1593 } diffstyle = DIFF_NONE; |
1827 * This should only be used for windows where 'diff' is set. | 1827 * This should only be used for windows where 'diff' is set. |
1828 */ | 1828 */ |
1829 int | 1829 int |
1830 diff_check(win_T *wp, linenr_T lnum) | 1830 diff_check(win_T *wp, linenr_T lnum) |
1831 { | 1831 { |
1832 int idx; /* index in tp_diffbuf[] for this buffer */ | 1832 int idx; // index in tp_diffbuf[] for this buffer |
1833 diff_T *dp; | 1833 diff_T *dp; |
1834 int maxcount; | 1834 int maxcount; |
1835 int i; | 1835 int i; |
1836 buf_T *buf = wp->w_buffer; | 1836 buf_T *buf = wp->w_buffer; |
1837 int cmp; | 1837 int cmp; |
1838 | 1838 |
1839 if (curtab->tp_diff_invalid) | 1839 if (curtab->tp_diff_invalid) |
1840 ex_diffupdate(NULL); /* update after a big change */ | 1840 ex_diffupdate(NULL); // update after a big change |
1841 | 1841 |
1842 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) /* no diffs at all */ | 1842 if (curtab->tp_first_diff == NULL || !wp->w_p_diff) // no diffs at all |
1843 return 0; | 1843 return 0; |
1844 | 1844 |
1845 /* safety check: "lnum" must be a buffer line */ | 1845 // safety check: "lnum" must be a buffer line |
1846 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) | 1846 if (lnum < 1 || lnum > buf->b_ml.ml_line_count + 1) |
1847 return 0; | 1847 return 0; |
1848 | 1848 |
1849 idx = diff_buf_idx(buf); | 1849 idx = diff_buf_idx(buf); |
1850 if (idx == DB_COUNT) | 1850 if (idx == DB_COUNT) |
1851 return 0; /* no diffs for buffer "buf" */ | 1851 return 0; // no diffs for buffer "buf" |
1852 | 1852 |
1853 #ifdef FEAT_FOLDING | 1853 #ifdef FEAT_FOLDING |
1854 /* A closed fold never has filler lines. */ | 1854 // A closed fold never has filler lines. |
1855 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) | 1855 if (hasFoldingWin(wp, lnum, NULL, NULL, TRUE, NULL)) |
1856 return 0; | 1856 return 0; |
1857 #endif | 1857 #endif |
1858 | 1858 |
1859 /* search for a change that includes "lnum" in the list of diffblocks. */ | 1859 // search for a change that includes "lnum" in the list of diffblocks. |
1860 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 1860 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
1861 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) | 1861 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
1862 break; | 1862 break; |
1863 if (dp == NULL || lnum < dp->df_lnum[idx]) | 1863 if (dp == NULL || lnum < dp->df_lnum[idx]) |
1864 return 0; | 1864 return 0; |
1865 | 1865 |
1866 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) | 1866 if (lnum < dp->df_lnum[idx] + dp->df_count[idx]) |
1867 { | 1867 { |
1868 int zero = FALSE; | 1868 int zero = FALSE; |
1869 | 1869 |
1870 /* Changed or inserted line. If the other buffers have a count of | 1870 // Changed or inserted line. If the other buffers have a count of |
1871 * zero, the lines were inserted. If the other buffers have the same | 1871 // zero, the lines were inserted. If the other buffers have the same |
1872 * count, check if the lines are identical. */ | 1872 // count, check if the lines are identical. |
1873 cmp = FALSE; | 1873 cmp = FALSE; |
1874 for (i = 0; i < DB_COUNT; ++i) | 1874 for (i = 0; i < DB_COUNT; ++i) |
1875 if (i != idx && curtab->tp_diffbuf[i] != NULL) | 1875 if (i != idx && curtab->tp_diffbuf[i] != NULL) |
1876 { | 1876 { |
1877 if (dp->df_count[i] == 0) | 1877 if (dp->df_count[i] == 0) |
1878 zero = TRUE; | 1878 zero = TRUE; |
1879 else | 1879 else |
1880 { | 1880 { |
1881 if (dp->df_count[i] != dp->df_count[idx]) | 1881 if (dp->df_count[i] != dp->df_count[idx]) |
1882 return -1; /* nr of lines changed. */ | 1882 return -1; // nr of lines changed. |
1883 cmp = TRUE; | 1883 cmp = TRUE; |
1884 } | 1884 } |
1885 } | 1885 } |
1886 if (cmp) | 1886 if (cmp) |
1887 { | 1887 { |
1888 /* Compare all lines. If they are equal the lines were inserted | 1888 // Compare all lines. If they are equal the lines were inserted |
1889 * in some buffers, deleted in others, but not changed. */ | 1889 // in some buffers, deleted in others, but not changed. |
1890 for (i = 0; i < DB_COUNT; ++i) | 1890 for (i = 0; i < DB_COUNT; ++i) |
1891 if (i != idx && curtab->tp_diffbuf[i] != NULL | 1891 if (i != idx && curtab->tp_diffbuf[i] != NULL |
1892 && dp->df_count[i] != 0) | 1892 && dp->df_count[i] != 0) |
1893 if (!diff_equal_entry(dp, idx, i)) | 1893 if (!diff_equal_entry(dp, idx, i)) |
1894 return -1; | 1894 return -1; |
1895 } | 1895 } |
1896 /* If there is no buffer with zero lines then there is no difference | 1896 // If there is no buffer with zero lines then there is no difference |
1897 * any longer. Happens when making a change (or undo) that removes | 1897 // any longer. Happens when making a change (or undo) that removes |
1898 * the difference. Can't remove the entry here, we might be halfway | 1898 // the difference. Can't remove the entry here, we might be halfway |
1899 * updating the window. Just report the text as unchanged. Other | 1899 // updating the window. Just report the text as unchanged. Other |
1900 * windows might still show the change though. */ | 1900 // windows might still show the change though. |
1901 if (zero == FALSE) | 1901 if (zero == FALSE) |
1902 return 0; | 1902 return 0; |
1903 return -2; | 1903 return -2; |
1904 } | 1904 } |
1905 | 1905 |
1906 /* If 'diffopt' doesn't contain "filler", return 0. */ | 1906 // If 'diffopt' doesn't contain "filler", return 0. |
1907 if (!(diff_flags & DIFF_FILLER)) | 1907 if (!(diff_flags & DIFF_FILLER)) |
1908 return 0; | 1908 return 0; |
1909 | 1909 |
1910 /* Insert filler lines above the line just below the change. Will return | 1910 // Insert filler lines above the line just below the change. Will return |
1911 * 0 when this buf had the max count. */ | 1911 // 0 when this buf had the max count. |
1912 maxcount = 0; | 1912 maxcount = 0; |
1913 for (i = 0; i < DB_COUNT; ++i) | 1913 for (i = 0; i < DB_COUNT; ++i) |
1914 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) | 1914 if (curtab->tp_diffbuf[i] != NULL && dp->df_count[i] > maxcount) |
1915 maxcount = dp->df_count[i]; | 1915 maxcount = dp->df_count[i]; |
1916 return maxcount - dp->df_count[idx]; | 1916 return maxcount - dp->df_count[idx]; |
2033 int | 2033 int |
2034 diff_check_fill(win_T *wp, linenr_T lnum) | 2034 diff_check_fill(win_T *wp, linenr_T lnum) |
2035 { | 2035 { |
2036 int n; | 2036 int n; |
2037 | 2037 |
2038 /* be quick when there are no filler lines */ | 2038 // be quick when there are no filler lines |
2039 if (!(diff_flags & DIFF_FILLER)) | 2039 if (!(diff_flags & DIFF_FILLER)) |
2040 return 0; | 2040 return 0; |
2041 n = diff_check(wp, lnum); | 2041 n = diff_check(wp, lnum); |
2042 if (n <= 0) | 2042 if (n <= 0) |
2043 return 0; | 2043 return 0; |
2059 int max_count; | 2059 int max_count; |
2060 int i; | 2060 int i; |
2061 | 2061 |
2062 fromidx = diff_buf_idx(frombuf); | 2062 fromidx = diff_buf_idx(frombuf); |
2063 if (fromidx == DB_COUNT) | 2063 if (fromidx == DB_COUNT) |
2064 return; /* safety check */ | 2064 return; // safety check |
2065 | 2065 |
2066 if (curtab->tp_diff_invalid) | 2066 if (curtab->tp_diff_invalid) |
2067 ex_diffupdate(NULL); /* update after a big change */ | 2067 ex_diffupdate(NULL); // update after a big change |
2068 | 2068 |
2069 towin->w_topfill = 0; | 2069 towin->w_topfill = 0; |
2070 | 2070 |
2071 /* search for a change that includes "lnum" in the list of diffblocks. */ | 2071 // search for a change that includes "lnum" in the list of diffblocks. |
2072 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 2072 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
2073 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) | 2073 if (lnum <= dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2074 break; | 2074 break; |
2075 if (dp == NULL) | 2075 if (dp == NULL) |
2076 { | 2076 { |
2077 /* After last change, compute topline relative to end of file; no | 2077 // After last change, compute topline relative to end of file; no |
2078 * filler lines. */ | 2078 // filler lines. |
2079 towin->w_topline = towin->w_buffer->b_ml.ml_line_count | 2079 towin->w_topline = towin->w_buffer->b_ml.ml_line_count |
2080 - (frombuf->b_ml.ml_line_count - lnum); | 2080 - (frombuf->b_ml.ml_line_count - lnum); |
2081 } | 2081 } |
2082 else | 2082 else |
2083 { | 2083 { |
2084 /* Find index for "towin". */ | 2084 // Find index for "towin". |
2085 toidx = diff_buf_idx(towin->w_buffer); | 2085 toidx = diff_buf_idx(towin->w_buffer); |
2086 if (toidx == DB_COUNT) | 2086 if (toidx == DB_COUNT) |
2087 return; /* safety check */ | 2087 return; // safety check |
2088 | 2088 |
2089 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); | 2089 towin->w_topline = lnum + (dp->df_lnum[toidx] - dp->df_lnum[fromidx]); |
2090 if (lnum >= dp->df_lnum[fromidx]) | 2090 if (lnum >= dp->df_lnum[fromidx]) |
2091 { | 2091 { |
2092 /* Inside a change: compute filler lines. With three or more | 2092 // Inside a change: compute filler lines. With three or more |
2093 * buffers we need to know the largest count. */ | 2093 // buffers we need to know the largest count. |
2094 max_count = 0; | 2094 max_count = 0; |
2095 for (i = 0; i < DB_COUNT; ++i) | 2095 for (i = 0; i < DB_COUNT; ++i) |
2096 if (curtab->tp_diffbuf[i] != NULL | 2096 if (curtab->tp_diffbuf[i] != NULL |
2097 && max_count < dp->df_count[i]) | 2097 && max_count < dp->df_count[i]) |
2098 max_count = dp->df_count[i]; | 2098 max_count = dp->df_count[i]; |
2099 | 2099 |
2100 if (dp->df_count[toidx] == dp->df_count[fromidx]) | 2100 if (dp->df_count[toidx] == dp->df_count[fromidx]) |
2101 { | 2101 { |
2102 /* same number of lines: use same filler count */ | 2102 // same number of lines: use same filler count |
2103 towin->w_topfill = fromwin->w_topfill; | 2103 towin->w_topfill = fromwin->w_topfill; |
2104 } | 2104 } |
2105 else if (dp->df_count[toidx] > dp->df_count[fromidx]) | 2105 else if (dp->df_count[toidx] > dp->df_count[fromidx]) |
2106 { | 2106 { |
2107 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) | 2107 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2108 { | 2108 { |
2109 /* more lines in towin and fromwin doesn't show diff | 2109 // more lines in towin and fromwin doesn't show diff |
2110 * lines, only filler lines */ | 2110 // lines, only filler lines |
2111 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) | 2111 if (max_count - fromwin->w_topfill >= dp->df_count[toidx]) |
2112 { | 2112 { |
2113 /* towin also only shows filler lines */ | 2113 // towin also only shows filler lines |
2114 towin->w_topline = dp->df_lnum[toidx] | 2114 towin->w_topline = dp->df_lnum[toidx] |
2115 + dp->df_count[toidx]; | 2115 + dp->df_count[toidx]; |
2116 towin->w_topfill = fromwin->w_topfill; | 2116 towin->w_topfill = fromwin->w_topfill; |
2117 } | 2117 } |
2118 else | 2118 else |
2119 /* towin still has some diff lines to show */ | 2119 // towin still has some diff lines to show |
2120 towin->w_topline = dp->df_lnum[toidx] | 2120 towin->w_topline = dp->df_lnum[toidx] |
2121 + max_count - fromwin->w_topfill; | 2121 + max_count - fromwin->w_topfill; |
2122 } | 2122 } |
2123 } | 2123 } |
2124 else if (towin->w_topline >= dp->df_lnum[toidx] | 2124 else if (towin->w_topline >= dp->df_lnum[toidx] |
2125 + dp->df_count[toidx]) | 2125 + dp->df_count[toidx]) |
2126 { | 2126 { |
2127 /* less lines in towin and no diff lines to show: compute | 2127 // less lines in towin and no diff lines to show: compute |
2128 * filler lines */ | 2128 // filler lines |
2129 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; | 2129 towin->w_topline = dp->df_lnum[toidx] + dp->df_count[toidx]; |
2130 if (diff_flags & DIFF_FILLER) | 2130 if (diff_flags & DIFF_FILLER) |
2131 { | 2131 { |
2132 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) | 2132 if (lnum == dp->df_lnum[fromidx] + dp->df_count[fromidx]) |
2133 /* fromwin is also out of diff lines */ | 2133 // fromwin is also out of diff lines |
2134 towin->w_topfill = fromwin->w_topfill; | 2134 towin->w_topfill = fromwin->w_topfill; |
2135 else | 2135 else |
2136 /* fromwin has some diff lines */ | 2136 // fromwin has some diff lines |
2137 towin->w_topfill = dp->df_lnum[fromidx] | 2137 towin->w_topfill = dp->df_lnum[fromidx] |
2138 + max_count - lnum; | 2138 + max_count - lnum; |
2139 } | 2139 } |
2140 } | 2140 } |
2141 } | 2141 } |
2142 } | 2142 } |
2143 | 2143 |
2144 /* safety check (if diff info gets outdated strange things may happen) */ | 2144 // safety check (if diff info gets outdated strange things may happen) |
2145 towin->w_botfill = FALSE; | 2145 towin->w_botfill = FALSE; |
2146 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) | 2146 if (towin->w_topline > towin->w_buffer->b_ml.ml_line_count) |
2147 { | 2147 { |
2148 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; | 2148 towin->w_topline = towin->w_buffer->b_ml.ml_line_count; |
2149 towin->w_botfill = TRUE; | 2149 towin->w_botfill = TRUE; |
2152 { | 2152 { |
2153 towin->w_topline = 1; | 2153 towin->w_topline = 1; |
2154 towin->w_topfill = 0; | 2154 towin->w_topfill = 0; |
2155 } | 2155 } |
2156 | 2156 |
2157 /* When w_topline changes need to recompute w_botline and cursor position */ | 2157 // When w_topline changes need to recompute w_botline and cursor position |
2158 invalidate_botline_win(towin); | 2158 invalidate_botline_win(towin); |
2159 changed_line_abv_curs_win(towin); | 2159 changed_line_abv_curs_win(towin); |
2160 | 2160 |
2161 check_topfill(towin, FALSE); | 2161 check_topfill(towin, FALSE); |
2162 #ifdef FEAT_FOLDING | 2162 #ifdef FEAT_FOLDING |
2285 ++p; | 2285 ++p; |
2286 } | 2286 } |
2287 | 2287 |
2288 diff_algorithm_new |= diff_indent_heuristic; | 2288 diff_algorithm_new |= diff_indent_heuristic; |
2289 | 2289 |
2290 /* Can't have both "horizontal" and "vertical". */ | 2290 // Can't have both "horizontal" and "vertical". |
2291 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) | 2291 if ((diff_flags_new & DIFF_HORIZONTAL) && (diff_flags_new & DIFF_VERTICAL)) |
2292 return FAIL; | 2292 return FAIL; |
2293 | 2293 |
2294 // If flags were added or removed, or the algorithm was changed, need to | 2294 // If flags were added or removed, or the algorithm was changed, need to |
2295 // update the diff. | 2295 // update the diff. |
2302 diff_foldcolumn = diff_foldcolumn_new; | 2302 diff_foldcolumn = diff_foldcolumn_new; |
2303 diff_algorithm = diff_algorithm_new; | 2303 diff_algorithm = diff_algorithm_new; |
2304 | 2304 |
2305 diff_redraw(TRUE); | 2305 diff_redraw(TRUE); |
2306 | 2306 |
2307 /* recompute the scroll binding with the new option value, may | 2307 // recompute the scroll binding with the new option value, may |
2308 * remove or add filler lines */ | 2308 // remove or add filler lines |
2309 check_scrollbind((linenr_T)0, 0L); | 2309 check_scrollbind((linenr_T)0, 0L); |
2310 | 2310 |
2311 return OK; | 2311 return OK; |
2312 } | 2312 } |
2313 | 2313 |
2344 */ | 2344 */ |
2345 int | 2345 int |
2346 diff_find_change( | 2346 diff_find_change( |
2347 win_T *wp, | 2347 win_T *wp, |
2348 linenr_T lnum, | 2348 linenr_T lnum, |
2349 int *startp, /* first char of the change */ | 2349 int *startp, // first char of the change |
2350 int *endp) /* last char of the change */ | 2350 int *endp) // last char of the change |
2351 { | 2351 { |
2352 char_u *line_org; | 2352 char_u *line_org; |
2353 char_u *line_new; | 2353 char_u *line_new; |
2354 int i; | 2354 int i; |
2355 int si_org, si_new; | 2355 int si_org, si_new; |
2359 int off; | 2359 int off; |
2360 int added = TRUE; | 2360 int added = TRUE; |
2361 char_u *p1, *p2; | 2361 char_u *p1, *p2; |
2362 int l; | 2362 int l; |
2363 | 2363 |
2364 /* Make a copy of the line, the next ml_get() will invalidate it. */ | 2364 // Make a copy of the line, the next ml_get() will invalidate it. |
2365 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); | 2365 line_org = vim_strsave(ml_get_buf(wp->w_buffer, lnum, FALSE)); |
2366 if (line_org == NULL) | 2366 if (line_org == NULL) |
2367 return FALSE; | 2367 return FALSE; |
2368 | 2368 |
2369 idx = diff_buf_idx(wp->w_buffer); | 2369 idx = diff_buf_idx(wp->w_buffer); |
2370 if (idx == DB_COUNT) /* cannot happen */ | 2370 if (idx == DB_COUNT) // cannot happen |
2371 { | 2371 { |
2372 vim_free(line_org); | 2372 vim_free(line_org); |
2373 return FALSE; | 2373 return FALSE; |
2374 } | 2374 } |
2375 | 2375 |
2376 /* search for a change that includes "lnum" in the list of diffblocks. */ | 2376 // search for a change that includes "lnum" in the list of diffblocks. |
2377 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 2377 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
2378 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) | 2378 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
2379 break; | 2379 break; |
2380 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) | 2380 if (dp == NULL || diff_check_sanity(curtab, dp) == FAIL) |
2381 { | 2381 { |
2386 off = lnum - dp->df_lnum[idx]; | 2386 off = lnum - dp->df_lnum[idx]; |
2387 | 2387 |
2388 for (i = 0; i < DB_COUNT; ++i) | 2388 for (i = 0; i < DB_COUNT; ++i) |
2389 if (curtab->tp_diffbuf[i] != NULL && i != idx) | 2389 if (curtab->tp_diffbuf[i] != NULL && i != idx) |
2390 { | 2390 { |
2391 /* Skip lines that are not in the other change (filler lines). */ | 2391 // Skip lines that are not in the other change (filler lines). |
2392 if (off >= dp->df_count[i]) | 2392 if (off >= dp->df_count[i]) |
2393 continue; | 2393 continue; |
2394 added = FALSE; | 2394 added = FALSE; |
2395 line_new = ml_get_buf(curtab->tp_diffbuf[i], | 2395 line_new = ml_get_buf(curtab->tp_diffbuf[i], |
2396 dp->df_lnum[i] + off, FALSE); | 2396 dp->df_lnum[i] + off, FALSE); |
2397 | 2397 |
2398 /* Search for start of difference */ | 2398 // Search for start of difference |
2399 si_org = si_new = 0; | 2399 si_org = si_new = 0; |
2400 while (line_org[si_org] != NUL) | 2400 while (line_org[si_org] != NUL) |
2401 { | 2401 { |
2402 if (((diff_flags & DIFF_IWHITE) | 2402 if (((diff_flags & DIFF_IWHITE) |
2403 && VIM_ISWHITE(line_org[si_org]) | 2403 && VIM_ISWHITE(line_org[si_org]) |
2418 si_new += l; | 2418 si_new += l; |
2419 } | 2419 } |
2420 } | 2420 } |
2421 if (has_mbyte) | 2421 if (has_mbyte) |
2422 { | 2422 { |
2423 /* Move back to first byte of character in both lines (may | 2423 // Move back to first byte of character in both lines (may |
2424 * have "nn^" in line_org and "n^ in line_new). */ | 2424 // have "nn^" in line_org and "n^ in line_new). |
2425 si_org -= (*mb_head_off)(line_org, line_org + si_org); | 2425 si_org -= (*mb_head_off)(line_org, line_org + si_org); |
2426 si_new -= (*mb_head_off)(line_new, line_new + si_new); | 2426 si_new -= (*mb_head_off)(line_new, line_new + si_new); |
2427 } | 2427 } |
2428 if (*startp > si_org) | 2428 if (*startp > si_org) |
2429 *startp = si_org; | 2429 *startp = si_org; |
2430 | 2430 |
2431 /* Search for end of difference, if any. */ | 2431 // Search for end of difference, if any. |
2432 if (line_org[si_org] != NUL || line_new[si_new] != NUL) | 2432 if (line_org[si_org] != NUL || line_new[si_new] != NUL) |
2433 { | 2433 { |
2434 ei_org = (int)STRLEN(line_org); | 2434 ei_org = (int)STRLEN(line_org); |
2435 ei_new = (int)STRLEN(line_new); | 2435 ei_new = (int)STRLEN(line_new); |
2436 while (ei_org >= *startp && ei_new >= si_new | 2436 while (ei_org >= *startp && ei_new >= si_new |
2483 int i; | 2483 int i; |
2484 int idx = -1; | 2484 int idx = -1; |
2485 int other = FALSE; | 2485 int other = FALSE; |
2486 diff_T *dp; | 2486 diff_T *dp; |
2487 | 2487 |
2488 /* Return if 'diff' isn't set. */ | 2488 // Return if 'diff' isn't set. |
2489 if (!wp->w_p_diff) | 2489 if (!wp->w_p_diff) |
2490 return FALSE; | 2490 return FALSE; |
2491 | 2491 |
2492 for (i = 0; i < DB_COUNT; ++i) | 2492 for (i = 0; i < DB_COUNT; ++i) |
2493 { | 2493 { |
2495 idx = i; | 2495 idx = i; |
2496 else if (curtab->tp_diffbuf[i] != NULL) | 2496 else if (curtab->tp_diffbuf[i] != NULL) |
2497 other = TRUE; | 2497 other = TRUE; |
2498 } | 2498 } |
2499 | 2499 |
2500 /* return here if there are no diffs in the window */ | 2500 // return here if there are no diffs in the window |
2501 if (idx == -1 || !other) | 2501 if (idx == -1 || !other) |
2502 return FALSE; | 2502 return FALSE; |
2503 | 2503 |
2504 if (curtab->tp_diff_invalid) | 2504 if (curtab->tp_diff_invalid) |
2505 ex_diffupdate(NULL); /* update after a big change */ | 2505 ex_diffupdate(NULL); // update after a big change |
2506 | 2506 |
2507 /* Return if there are no diff blocks. All lines will be folded. */ | 2507 // Return if there are no diff blocks. All lines will be folded. |
2508 if (curtab->tp_first_diff == NULL) | 2508 if (curtab->tp_first_diff == NULL) |
2509 return TRUE; | 2509 return TRUE; |
2510 | 2510 |
2511 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 2511 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
2512 { | 2512 { |
2513 /* If this change is below the line there can't be any further match. */ | 2513 // If this change is below the line there can't be any further match. |
2514 if (dp->df_lnum[idx] - diff_context > lnum) | 2514 if (dp->df_lnum[idx] - diff_context > lnum) |
2515 break; | 2515 break; |
2516 /* If this change ends before the line we have a match. */ | 2516 // If this change ends before the line we have a match. |
2517 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) | 2517 if (dp->df_lnum[idx] + dp->df_count[idx] + diff_context > lnum) |
2518 return FALSE; | 2518 return FALSE; |
2519 } | 2519 } |
2520 return TRUE; | 2520 return TRUE; |
2521 } | 2521 } |
2579 int start_skip, end_skip; | 2579 int start_skip, end_skip; |
2580 int new_count; | 2580 int new_count; |
2581 int buf_empty; | 2581 int buf_empty; |
2582 int found_not_ma = FALSE; | 2582 int found_not_ma = FALSE; |
2583 | 2583 |
2584 /* Find the current buffer in the list of diff buffers. */ | 2584 // Find the current buffer in the list of diff buffers. |
2585 idx_cur = diff_buf_idx(curbuf); | 2585 idx_cur = diff_buf_idx(curbuf); |
2586 if (idx_cur == DB_COUNT) | 2586 if (idx_cur == DB_COUNT) |
2587 { | 2587 { |
2588 emsg(_("E99: Current buffer is not in diff mode")); | 2588 emsg(_("E99: Current buffer is not in diff mode")); |
2589 return; | 2589 return; |
2590 } | 2590 } |
2591 | 2591 |
2592 if (*eap->arg == NUL) | 2592 if (*eap->arg == NUL) |
2593 { | 2593 { |
2594 /* No argument: Find the other buffer in the list of diff buffers. */ | 2594 // No argument: Find the other buffer in the list of diff buffers. |
2595 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) | 2595 for (idx_other = 0; idx_other < DB_COUNT; ++idx_other) |
2596 if (curtab->tp_diffbuf[idx_other] != curbuf | 2596 if (curtab->tp_diffbuf[idx_other] != curbuf |
2597 && curtab->tp_diffbuf[idx_other] != NULL) | 2597 && curtab->tp_diffbuf[idx_other] != NULL) |
2598 { | 2598 { |
2599 if (eap->cmdidx != CMD_diffput | 2599 if (eap->cmdidx != CMD_diffput |
2608 else | 2608 else |
2609 emsg(_("E100: No other buffer in diff mode")); | 2609 emsg(_("E100: No other buffer in diff mode")); |
2610 return; | 2610 return; |
2611 } | 2611 } |
2612 | 2612 |
2613 /* Check that there isn't a third buffer in the list */ | 2613 // Check that there isn't a third buffer in the list |
2614 for (i = idx_other + 1; i < DB_COUNT; ++i) | 2614 for (i = idx_other + 1; i < DB_COUNT; ++i) |
2615 if (curtab->tp_diffbuf[i] != curbuf | 2615 if (curtab->tp_diffbuf[i] != curbuf |
2616 && curtab->tp_diffbuf[i] != NULL | 2616 && curtab->tp_diffbuf[i] != NULL |
2617 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) | 2617 && (eap->cmdidx != CMD_diffput || curtab->tp_diffbuf[i]->b_p_ma)) |
2618 { | 2618 { |
2620 return; | 2620 return; |
2621 } | 2621 } |
2622 } | 2622 } |
2623 else | 2623 else |
2624 { | 2624 { |
2625 /* Buffer number or pattern given. Ignore trailing white space. */ | 2625 // Buffer number or pattern given. Ignore trailing white space. |
2626 p = eap->arg + STRLEN(eap->arg); | 2626 p = eap->arg + STRLEN(eap->arg); |
2627 while (p > eap->arg && VIM_ISWHITE(p[-1])) | 2627 while (p > eap->arg && VIM_ISWHITE(p[-1])) |
2628 --p; | 2628 --p; |
2629 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) | 2629 for (i = 0; vim_isdigit(eap->arg[i]) && eap->arg + i < p; ++i) |
2630 ; | 2630 ; |
2631 if (eap->arg + i == p) /* digits only */ | 2631 if (eap->arg + i == p) // digits only |
2632 i = atol((char *)eap->arg); | 2632 i = atol((char *)eap->arg); |
2633 else | 2633 else |
2634 { | 2634 { |
2635 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); | 2635 i = buflist_findpat(eap->arg, p, FALSE, TRUE, FALSE); |
2636 if (i < 0) | 2636 if (i < 0) |
2637 return; /* error message already given */ | 2637 return; // error message already given |
2638 } | 2638 } |
2639 buf = buflist_findnr(i); | 2639 buf = buflist_findnr(i); |
2640 if (buf == NULL) | 2640 if (buf == NULL) |
2641 { | 2641 { |
2642 semsg(_("E102: Can't find buffer \"%s\""), eap->arg); | 2642 semsg(_("E102: Can't find buffer \"%s\""), eap->arg); |
2643 return; | 2643 return; |
2644 } | 2644 } |
2645 if (buf == curbuf) | 2645 if (buf == curbuf) |
2646 return; /* nothing to do */ | 2646 return; // nothing to do |
2647 idx_other = diff_buf_idx(buf); | 2647 idx_other = diff_buf_idx(buf); |
2648 if (idx_other == DB_COUNT) | 2648 if (idx_other == DB_COUNT) |
2649 { | 2649 { |
2650 semsg(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); | 2650 semsg(_("E103: Buffer \"%s\" is not in diff mode"), eap->arg); |
2651 return; | 2651 return; |
2652 } | 2652 } |
2653 } | 2653 } |
2654 | 2654 |
2655 diff_busy = TRUE; | 2655 diff_busy = TRUE; |
2656 | 2656 |
2657 /* When no range given include the line above or below the cursor. */ | 2657 // When no range given include the line above or below the cursor. |
2658 if (eap->addr_count == 0) | 2658 if (eap->addr_count == 0) |
2659 { | 2659 { |
2660 /* Make it possible that ":diffget" on the last line gets line below | 2660 // Make it possible that ":diffget" on the last line gets line below |
2661 * the cursor line when there is no difference above the cursor. */ | 2661 // the cursor line when there is no difference above the cursor. |
2662 if (eap->cmdidx == CMD_diffget | 2662 if (eap->cmdidx == CMD_diffget |
2663 && eap->line1 == curbuf->b_ml.ml_line_count | 2663 && eap->line1 == curbuf->b_ml.ml_line_count |
2664 && diff_check(curwin, eap->line1) == 0 | 2664 && diff_check(curwin, eap->line1) == 0 |
2665 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) | 2665 && (eap->line1 == 1 || diff_check(curwin, eap->line1 - 1) == 0)) |
2666 ++eap->line2; | 2666 ++eap->line2; |
2675 } | 2675 } |
2676 else | 2676 else |
2677 { | 2677 { |
2678 idx_from = idx_cur; | 2678 idx_from = idx_cur; |
2679 idx_to = idx_other; | 2679 idx_to = idx_other; |
2680 /* Need to make the other buffer the current buffer to be able to make | 2680 // Need to make the other buffer the current buffer to be able to make |
2681 * changes in it. */ | 2681 // changes in it. |
2682 /* set curwin/curbuf to buf and save a few things */ | 2682 // set curwin/curbuf to buf and save a few things |
2683 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); | 2683 aucmd_prepbuf(&aco, curtab->tp_diffbuf[idx_other]); |
2684 } | 2684 } |
2685 | 2685 |
2686 /* May give the warning for a changed buffer here, which can trigger the | 2686 // May give the warning for a changed buffer here, which can trigger the |
2687 * FileChangedRO autocommand, which may do nasty things and mess | 2687 // FileChangedRO autocommand, which may do nasty things and mess |
2688 * everything up. */ | 2688 // everything up. |
2689 if (!curbuf->b_changed) | 2689 if (!curbuf->b_changed) |
2690 { | 2690 { |
2691 change_warning(0); | 2691 change_warning(0); |
2692 if (diff_buf_idx(curbuf) != idx_to) | 2692 if (diff_buf_idx(curbuf) != idx_to) |
2693 { | 2693 { |
2698 | 2698 |
2699 dprev = NULL; | 2699 dprev = NULL; |
2700 for (dp = curtab->tp_first_diff; dp != NULL; ) | 2700 for (dp = curtab->tp_first_diff; dp != NULL; ) |
2701 { | 2701 { |
2702 if (dp->df_lnum[idx_cur] > eap->line2 + off) | 2702 if (dp->df_lnum[idx_cur] > eap->line2 + off) |
2703 break; /* past the range that was specified */ | 2703 break; // past the range that was specified |
2704 | 2704 |
2705 dfree = NULL; | 2705 dfree = NULL; |
2706 lnum = dp->df_lnum[idx_to]; | 2706 lnum = dp->df_lnum[idx_to]; |
2707 count = dp->df_count[idx_to]; | 2707 count = dp->df_count[idx_to]; |
2708 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off | 2708 if (dp->df_lnum[idx_cur] + dp->df_count[idx_cur] > eap->line1 + off |
2709 && u_save(lnum - 1, lnum + count) != FAIL) | 2709 && u_save(lnum - 1, lnum + count) != FAIL) |
2710 { | 2710 { |
2711 /* Inside the specified range and saving for undo worked. */ | 2711 // Inside the specified range and saving for undo worked. |
2712 start_skip = 0; | 2712 start_skip = 0; |
2713 end_skip = 0; | 2713 end_skip = 0; |
2714 if (eap->addr_count > 0) | 2714 if (eap->addr_count > 0) |
2715 { | 2715 { |
2716 /* A range was specified: check if lines need to be skipped. */ | 2716 // A range was specified: check if lines need to be skipped. |
2717 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; | 2717 start_skip = eap->line1 + off - dp->df_lnum[idx_cur]; |
2718 if (start_skip > 0) | 2718 if (start_skip > 0) |
2719 { | 2719 { |
2720 /* range starts below start of current diff block */ | 2720 // range starts below start of current diff block |
2721 if (start_skip > count) | 2721 if (start_skip > count) |
2722 { | 2722 { |
2723 lnum += count; | 2723 lnum += count; |
2724 count = 0; | 2724 count = 0; |
2725 } | 2725 } |
2734 | 2734 |
2735 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 | 2735 end_skip = dp->df_lnum[idx_cur] + dp->df_count[idx_cur] - 1 |
2736 - (eap->line2 + off); | 2736 - (eap->line2 + off); |
2737 if (end_skip > 0) | 2737 if (end_skip > 0) |
2738 { | 2738 { |
2739 /* range ends above end of current/from diff block */ | 2739 // range ends above end of current/from diff block |
2740 if (idx_cur == idx_from) /* :diffput */ | 2740 if (idx_cur == idx_from) // :diffput |
2741 { | 2741 { |
2742 i = dp->df_count[idx_cur] - start_skip - end_skip; | 2742 i = dp->df_count[idx_cur] - start_skip - end_skip; |
2743 if (count > i) | 2743 if (count > i) |
2744 count = i; | 2744 count = i; |
2745 } | 2745 } |
2746 else /* :diffget */ | 2746 else // :diffget |
2747 { | 2747 { |
2748 count -= end_skip; | 2748 count -= end_skip; |
2749 end_skip = dp->df_count[idx_from] - start_skip - count; | 2749 end_skip = dp->df_count[idx_from] - start_skip - count; |
2750 if (end_skip < 0) | 2750 if (end_skip < 0) |
2751 end_skip = 0; | 2751 end_skip = 0; |
2757 | 2757 |
2758 buf_empty = BUFEMPTY(); | 2758 buf_empty = BUFEMPTY(); |
2759 added = 0; | 2759 added = 0; |
2760 for (i = 0; i < count; ++i) | 2760 for (i = 0; i < count; ++i) |
2761 { | 2761 { |
2762 /* remember deleting the last line of the buffer */ | 2762 // remember deleting the last line of the buffer |
2763 buf_empty = curbuf->b_ml.ml_line_count == 1; | 2763 buf_empty = curbuf->b_ml.ml_line_count == 1; |
2764 ml_delete(lnum, FALSE); | 2764 ml_delete(lnum, FALSE); |
2765 --added; | 2765 --added; |
2766 } | 2766 } |
2767 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) | 2767 for (i = 0; i < dp->df_count[idx_from] - start_skip - end_skip; ++i) |
2778 ml_append(lnum + i - 1, p, 0, FALSE); | 2778 ml_append(lnum + i - 1, p, 0, FALSE); |
2779 vim_free(p); | 2779 vim_free(p); |
2780 ++added; | 2780 ++added; |
2781 if (buf_empty && curbuf->b_ml.ml_line_count == 2) | 2781 if (buf_empty && curbuf->b_ml.ml_line_count == 2) |
2782 { | 2782 { |
2783 /* Added the first line into an empty buffer, need to | 2783 // Added the first line into an empty buffer, need to |
2784 * delete the dummy empty line. */ | 2784 // delete the dummy empty line. |
2785 buf_empty = FALSE; | 2785 buf_empty = FALSE; |
2786 ml_delete((linenr_T)2, FALSE); | 2786 ml_delete((linenr_T)2, FALSE); |
2787 } | 2787 } |
2788 } | 2788 } |
2789 } | 2789 } |
2790 new_count = dp->df_count[idx_to] + added; | 2790 new_count = dp->df_count[idx_to] + added; |
2791 dp->df_count[idx_to] = new_count; | 2791 dp->df_count[idx_to] = new_count; |
2792 | 2792 |
2793 if (start_skip == 0 && end_skip == 0) | 2793 if (start_skip == 0 && end_skip == 0) |
2794 { | 2794 { |
2795 /* Check if there are any other buffers and if the diff is | 2795 // Check if there are any other buffers and if the diff is |
2796 * equal in them. */ | 2796 // equal in them. |
2797 for (i = 0; i < DB_COUNT; ++i) | 2797 for (i = 0; i < DB_COUNT; ++i) |
2798 if (curtab->tp_diffbuf[i] != NULL && i != idx_from | 2798 if (curtab->tp_diffbuf[i] != NULL && i != idx_from |
2799 && i != idx_to | 2799 && i != idx_to |
2800 && !diff_equal_entry(dp, idx_from, i)) | 2800 && !diff_equal_entry(dp, idx_from, i)) |
2801 break; | 2801 break; |
2802 if (i == DB_COUNT) | 2802 if (i == DB_COUNT) |
2803 { | 2803 { |
2804 /* delete the diff entry, the buffers are now equal here */ | 2804 // delete the diff entry, the buffers are now equal here |
2805 dfree = dp; | 2805 dfree = dp; |
2806 dp = dp->df_next; | 2806 dp = dp->df_next; |
2807 if (dprev == NULL) | 2807 if (dprev == NULL) |
2808 curtab->tp_first_diff = dp; | 2808 curtab->tp_first_diff = dp; |
2809 else | 2809 else |
2810 dprev->df_next = dp; | 2810 dprev->df_next = dp; |
2811 } | 2811 } |
2812 } | 2812 } |
2813 | 2813 |
2814 /* Adjust marks. This will change the following entries! */ | 2814 // Adjust marks. This will change the following entries! |
2815 if (added != 0) | 2815 if (added != 0) |
2816 { | 2816 { |
2817 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); | 2817 mark_adjust(lnum, lnum + count - 1, (long)MAXLNUM, (long)added); |
2818 if (curwin->w_cursor.lnum >= lnum) | 2818 if (curwin->w_cursor.lnum >= lnum) |
2819 { | 2819 { |
2820 /* Adjust the cursor position if it's in/after the changed | 2820 // Adjust the cursor position if it's in/after the changed |
2821 * lines. */ | 2821 // lines. |
2822 if (curwin->w_cursor.lnum >= lnum + count) | 2822 if (curwin->w_cursor.lnum >= lnum + count) |
2823 curwin->w_cursor.lnum += added; | 2823 curwin->w_cursor.lnum += added; |
2824 else if (added < 0) | 2824 else if (added < 0) |
2825 curwin->w_cursor.lnum = lnum; | 2825 curwin->w_cursor.lnum = lnum; |
2826 } | 2826 } |
2827 } | 2827 } |
2828 changed_lines(lnum, 0, lnum + count, (long)added); | 2828 changed_lines(lnum, 0, lnum + count, (long)added); |
2829 | 2829 |
2830 if (dfree != NULL) | 2830 if (dfree != NULL) |
2831 { | 2831 { |
2832 /* Diff is deleted, update folds in other windows. */ | 2832 // Diff is deleted, update folds in other windows. |
2833 #ifdef FEAT_FOLDING | 2833 #ifdef FEAT_FOLDING |
2834 diff_fold_update(dfree, idx_to); | 2834 diff_fold_update(dfree, idx_to); |
2835 #endif | 2835 #endif |
2836 vim_free(dfree); | 2836 vim_free(dfree); |
2837 } | 2837 } |
2838 else | 2838 else |
2839 /* mark_adjust() may have changed the count in a wrong way */ | 2839 // mark_adjust() may have changed the count in a wrong way |
2840 dp->df_count[idx_to] = new_count; | 2840 dp->df_count[idx_to] = new_count; |
2841 | 2841 |
2842 /* When changing the current buffer, keep track of line numbers */ | 2842 // When changing the current buffer, keep track of line numbers |
2843 if (idx_cur == idx_to) | 2843 if (idx_cur == idx_to) |
2844 off += added; | 2844 off += added; |
2845 } | 2845 } |
2846 | 2846 |
2847 /* If before the range or not deleted, go to next diff. */ | 2847 // If before the range or not deleted, go to next diff. |
2848 if (dfree == NULL) | 2848 if (dfree == NULL) |
2849 { | 2849 { |
2850 dprev = dp; | 2850 dprev = dp; |
2851 dp = dp->df_next; | 2851 dp = dp->df_next; |
2852 } | 2852 } |
2853 } | 2853 } |
2854 | 2854 |
2855 /* restore curwin/curbuf and a few other things */ | 2855 // restore curwin/curbuf and a few other things |
2856 if (eap->cmdidx != CMD_diffget) | 2856 if (eap->cmdidx != CMD_diffget) |
2857 { | 2857 { |
2858 /* Syncing undo only works for the current buffer, but we change | 2858 // Syncing undo only works for the current buffer, but we change |
2859 * another buffer. Sync undo if the command was typed. This isn't | 2859 // another buffer. Sync undo if the command was typed. This isn't |
2860 * 100% right when ":diffput" is used in a function or mapping. */ | 2860 // 100% right when ":diffput" is used in a function or mapping. |
2861 if (KeyTyped) | 2861 if (KeyTyped) |
2862 u_sync(FALSE); | 2862 u_sync(FALSE); |
2863 aucmd_restbuf(&aco); | 2863 aucmd_restbuf(&aco); |
2864 } | 2864 } |
2865 | 2865 |
2933 idx = diff_buf_idx(curbuf); | 2933 idx = diff_buf_idx(curbuf); |
2934 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) | 2934 if (idx == DB_COUNT || curtab->tp_first_diff == NULL) |
2935 return FAIL; | 2935 return FAIL; |
2936 | 2936 |
2937 if (curtab->tp_diff_invalid) | 2937 if (curtab->tp_diff_invalid) |
2938 ex_diffupdate(NULL); /* update after a big change */ | 2938 ex_diffupdate(NULL); // update after a big change |
2939 | 2939 |
2940 if (curtab->tp_first_diff == NULL) /* no diffs today */ | 2940 if (curtab->tp_first_diff == NULL) // no diffs today |
2941 return FAIL; | 2941 return FAIL; |
2942 | 2942 |
2943 while (--count >= 0) | 2943 while (--count >= 0) |
2944 { | 2944 { |
2945 /* Check if already before first diff. */ | 2945 // Check if already before first diff. |
2946 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) | 2946 if (dir == BACKWARD && lnum <= curtab->tp_first_diff->df_lnum[idx]) |
2947 break; | 2947 break; |
2948 | 2948 |
2949 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) | 2949 for (dp = curtab->tp_first_diff; ; dp = dp->df_next) |
2950 { | 2950 { |
2959 break; | 2959 break; |
2960 } | 2960 } |
2961 } | 2961 } |
2962 } | 2962 } |
2963 | 2963 |
2964 /* don't end up past the end of the file */ | 2964 // don't end up past the end of the file |
2965 if (lnum > curbuf->b_ml.ml_line_count) | 2965 if (lnum > curbuf->b_ml.ml_line_count) |
2966 lnum = curbuf->b_ml.ml_line_count; | 2966 lnum = curbuf->b_ml.ml_line_count; |
2967 | 2967 |
2968 /* When the cursor didn't move at all we fail. */ | 2968 // When the cursor didn't move at all we fail. |
2969 if (lnum == curwin->w_cursor.lnum) | 2969 if (lnum == curwin->w_cursor.lnum) |
2970 return FAIL; | 2970 return FAIL; |
2971 | 2971 |
2972 setpcmark(); | 2972 setpcmark(); |
2973 curwin->w_cursor.lnum = lnum; | 2973 curwin->w_cursor.lnum = lnum; |
2994 idx2 = diff_buf_idx(curbuf); | 2994 idx2 = diff_buf_idx(curbuf); |
2995 if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL) | 2995 if (idx1 == DB_COUNT || idx2 == DB_COUNT || curtab->tp_first_diff == NULL) |
2996 return lnum1; | 2996 return lnum1; |
2997 | 2997 |
2998 if (curtab->tp_diff_invalid) | 2998 if (curtab->tp_diff_invalid) |
2999 ex_diffupdate(NULL); /* update after a big change */ | 2999 ex_diffupdate(NULL); // update after a big change |
3000 | 3000 |
3001 if (curtab->tp_first_diff == NULL) /* no diffs today */ | 3001 if (curtab->tp_first_diff == NULL) // no diffs today |
3002 return lnum1; | 3002 return lnum1; |
3003 | 3003 |
3004 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 3004 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
3005 { | 3005 { |
3006 if (dp->df_lnum[idx1] > lnum1) | 3006 if (dp->df_lnum[idx1] > lnum1) |
3007 return lnum1 - baseline; | 3007 return lnum1 - baseline; |
3008 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) | 3008 if ((dp->df_lnum[idx1] + dp->df_count[idx1]) > lnum1) |
3009 { | 3009 { |
3010 /* Inside the diffblock */ | 3010 // Inside the diffblock |
3011 baseline = lnum1 - dp->df_lnum[idx1]; | 3011 baseline = lnum1 - dp->df_lnum[idx1]; |
3012 if (baseline > dp->df_count[idx2]) | 3012 if (baseline > dp->df_count[idx2]) |
3013 baseline = dp->df_count[idx2]; | 3013 baseline = dp->df_count[idx2]; |
3014 | 3014 |
3015 return dp->df_lnum[idx2] + baseline; | 3015 return dp->df_lnum[idx2] + baseline; |
3029 return curwin->w_cursor.lnum; | 3029 return curwin->w_cursor.lnum; |
3030 baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) | 3030 baseline = (dp->df_lnum[idx1] + dp->df_count[idx1]) |
3031 - (dp->df_lnum[idx2] + dp->df_count[idx2]); | 3031 - (dp->df_lnum[idx2] + dp->df_count[idx2]); |
3032 } | 3032 } |
3033 | 3033 |
3034 /* If we get here then the cursor is after the last diff */ | 3034 // If we get here then the cursor is after the last diff |
3035 return lnum1 - baseline; | 3035 return lnum1 - baseline; |
3036 } | 3036 } |
3037 | 3037 |
3038 /* | 3038 /* |
3039 * Return the line number in the current window that is closest to "lnum1" in | 3039 * Return the line number in the current window that is closest to "lnum1" in |
3042 linenr_T | 3042 linenr_T |
3043 diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1) | 3043 diff_get_corresponding_line(buf_T *buf1, linenr_T lnum1) |
3044 { | 3044 { |
3045 linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); | 3045 linenr_T lnum = diff_get_corresponding_line_int(buf1, lnum1); |
3046 | 3046 |
3047 /* don't end up past the end of the file */ | 3047 // don't end up past the end of the file |
3048 if (lnum > curbuf->b_ml.ml_line_count) | 3048 if (lnum > curbuf->b_ml.ml_line_count) |
3049 return curbuf->b_ml.ml_line_count; | 3049 return curbuf->b_ml.ml_line_count; |
3050 return lnum; | 3050 return lnum; |
3051 } | 3051 } |
3052 | 3052 |
3061 int idx; | 3061 int idx; |
3062 int i; | 3062 int i; |
3063 linenr_T n; | 3063 linenr_T n; |
3064 | 3064 |
3065 idx = diff_buf_idx(curbuf); | 3065 idx = diff_buf_idx(curbuf); |
3066 if (idx == DB_COUNT) /* safety check */ | 3066 if (idx == DB_COUNT) // safety check |
3067 return (linenr_T)0; | 3067 return (linenr_T)0; |
3068 | 3068 |
3069 if (curtab->tp_diff_invalid) | 3069 if (curtab->tp_diff_invalid) |
3070 ex_diffupdate(NULL); /* update after a big change */ | 3070 ex_diffupdate(NULL); // update after a big change |
3071 | 3071 |
3072 /* search for a change that includes "lnum" in the list of diffblocks. */ | 3072 // search for a change that includes "lnum" in the list of diffblocks. |
3073 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) | 3073 for (dp = curtab->tp_first_diff; dp != NULL; dp = dp->df_next) |
3074 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) | 3074 if (lnum <= dp->df_lnum[idx] + dp->df_count[idx]) |
3075 break; | 3075 break; |
3076 | 3076 |
3077 /* When after the last change, compute relative to the last line number. */ | 3077 // When after the last change, compute relative to the last line number. |
3078 if (dp == NULL) | 3078 if (dp == NULL) |
3079 return wp->w_buffer->b_ml.ml_line_count | 3079 return wp->w_buffer->b_ml.ml_line_count |
3080 - (curbuf->b_ml.ml_line_count - lnum); | 3080 - (curbuf->b_ml.ml_line_count - lnum); |
3081 | 3081 |
3082 /* Find index for "wp". */ | 3082 // Find index for "wp". |
3083 i = diff_buf_idx(wp->w_buffer); | 3083 i = diff_buf_idx(wp->w_buffer); |
3084 if (i == DB_COUNT) /* safety check */ | 3084 if (i == DB_COUNT) // safety check |
3085 return (linenr_T)0; | 3085 return (linenr_T)0; |
3086 | 3086 |
3087 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); | 3087 n = lnum + (dp->df_lnum[i] - dp->df_lnum[idx]); |
3088 if (n > dp->df_lnum[i] + dp->df_count[i]) | 3088 if (n > dp->df_lnum[i] + dp->df_count[i]) |
3089 n = dp->df_lnum[i] + dp->df_count[i]; | 3089 n = dp->df_lnum[i] + dp->df_count[i]; |
3274 static int change_end = 0; | 3274 static int change_end = 0; |
3275 static hlf_T hlID = (hlf_T)0; | 3275 static hlf_T hlID = (hlf_T)0; |
3276 int filler_lines; | 3276 int filler_lines; |
3277 int col; | 3277 int col; |
3278 | 3278 |
3279 if (lnum < 0) /* ignore type error in {lnum} arg */ | 3279 if (lnum < 0) // ignore type error in {lnum} arg |
3280 lnum = 0; | 3280 lnum = 0; |
3281 if (lnum != prev_lnum | 3281 if (lnum != prev_lnum |
3282 || changedtick != CHANGEDTICK(curbuf) | 3282 || changedtick != CHANGEDTICK(curbuf) |
3283 || fnum != curbuf->b_fnum) | 3283 || fnum != curbuf->b_fnum) |
3284 { | 3284 { |
3285 /* New line, buffer, change: need to get the values. */ | 3285 // New line, buffer, change: need to get the values. |
3286 filler_lines = diff_check(curwin, lnum); | 3286 filler_lines = diff_check(curwin, lnum); |
3287 if (filler_lines < 0) | 3287 if (filler_lines < 0) |
3288 { | 3288 { |
3289 if (filler_lines == -1) | 3289 if (filler_lines == -1) |
3290 { | 3290 { |
3291 change_start = MAXCOL; | 3291 change_start = MAXCOL; |
3292 change_end = -1; | 3292 change_end = -1; |
3293 if (diff_find_change(curwin, lnum, &change_start, &change_end)) | 3293 if (diff_find_change(curwin, lnum, &change_start, &change_end)) |
3294 hlID = HLF_ADD; /* added line */ | 3294 hlID = HLF_ADD; // added line |
3295 else | 3295 else |
3296 hlID = HLF_CHD; /* changed line */ | 3296 hlID = HLF_CHD; // changed line |
3297 } | 3297 } |
3298 else | 3298 else |
3299 hlID = HLF_ADD; /* added line */ | 3299 hlID = HLF_ADD; // added line |
3300 } | 3300 } |
3301 else | 3301 else |
3302 hlID = (hlf_T)0; | 3302 hlID = (hlf_T)0; |
3303 prev_lnum = lnum; | 3303 prev_lnum = lnum; |
3304 changedtick = CHANGEDTICK(curbuf); | 3304 changedtick = CHANGEDTICK(curbuf); |
3305 fnum = curbuf->b_fnum; | 3305 fnum = curbuf->b_fnum; |
3306 } | 3306 } |
3307 | 3307 |
3308 if (hlID == HLF_CHD || hlID == HLF_TXD) | 3308 if (hlID == HLF_CHD || hlID == HLF_TXD) |
3309 { | 3309 { |
3310 col = tv_get_number(&argvars[1]) - 1; /* ignore type error in {col} */ | 3310 col = tv_get_number(&argvars[1]) - 1; // ignore type error in {col} |
3311 if (col >= change_start && col <= change_end) | 3311 if (col >= change_start && col <= change_end) |
3312 hlID = HLF_TXD; /* changed text */ | 3312 hlID = HLF_TXD; // changed text |
3313 else | 3313 else |
3314 hlID = HLF_CHD; /* changed line */ | 3314 hlID = HLF_CHD; // changed line |
3315 } | 3315 } |
3316 rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; | 3316 rettv->vval.v_number = hlID == (hlf_T)0 ? 0 : (int)hlID; |
3317 #endif | 3317 #endif |
3318 } | 3318 } |
3319 | 3319 |