Mercurial > vim
comparison src/buffer.c @ 12477:68d7bc045dbe v8.0.1118
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
commit https://github.com/vim/vim/commit/4033c55eca575777718c0701e26635a0cc47d907
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Sep 16 20:54:51 2017 +0200
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Problem: FEAT_WINDOWS adds a lot of #ifdefs while it is nearly always
enabled and only adds 7% to the binary size of the tiny build.
Solution: Graduate FEAT_WINDOWS.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 16 Sep 2017 21:00:06 +0200 |
parents | 1ecdbc207c1e |
children | 65c7769ef6d1 |
comparison
equal
deleted
inserted
replaced
12476:2516383741e6 | 12477:68d7bc045dbe |
---|---|
57 | 57 |
58 #if defined(FEAT_SIGNS) | 58 #if defined(FEAT_SIGNS) |
59 static void insert_sign(buf_T *buf, signlist_T *prev, signlist_T *next, int id, linenr_T lnum, int typenr); | 59 static void insert_sign(buf_T *buf, signlist_T *prev, signlist_T *next, int id, linenr_T lnum, int typenr); |
60 #endif | 60 #endif |
61 | 61 |
62 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 62 #if defined(FEAT_QUICKFIX) |
63 static char *msg_loclist = N_("[Location List]"); | 63 static char *msg_loclist = N_("[Location List]"); |
64 static char *msg_qflist = N_("[Quickfix List]"); | 64 static char *msg_qflist = N_("[Quickfix List]"); |
65 #endif | 65 #endif |
66 #ifdef FEAT_AUTOCMD | 66 #ifdef FEAT_AUTOCMD |
67 static char *e_auabort = N_("E855: Autocommands caused command to abort"); | 67 static char *e_auabort = N_("E855: Autocommands caused command to abort"); |
456 { | 456 { |
457 #ifdef FEAT_AUTOCMD | 457 #ifdef FEAT_AUTOCMD |
458 int is_curbuf; | 458 int is_curbuf; |
459 int nwindows; | 459 int nwindows; |
460 bufref_T bufref; | 460 bufref_T bufref; |
461 # ifdef FEAT_WINDOWS | |
462 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); | 461 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
463 win_T *the_curwin = curwin; | 462 win_T *the_curwin = curwin; |
464 tabpage_T *the_curtab = curtab; | 463 tabpage_T *the_curtab = curtab; |
465 # endif | |
466 #endif | 464 #endif |
467 int unload_buf = (action != 0); | 465 int unload_buf = (action != 0); |
468 int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); | 466 int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); |
469 int wipe_buf = (action == DOBUF_WIPE); | 467 int wipe_buf = (action == DOBUF_WIPE); |
470 | 468 |
520 EMSG(_("E937: Attempt to delete a buffer that is in use")); | 518 EMSG(_("E937: Attempt to delete a buffer that is in use")); |
521 return; | 519 return; |
522 } | 520 } |
523 #endif | 521 #endif |
524 | 522 |
525 if (win != NULL | 523 /* check no autocommands closed the window */ |
526 #ifdef FEAT_WINDOWS | 524 if (win != NULL && win_valid_any_tab(win)) |
527 && win_valid_any_tab(win) /* in case autocommands closed the window */ | |
528 #endif | |
529 ) | |
530 { | 525 { |
531 /* Set b_last_cursor when closing the last window for the buffer. | 526 /* Set b_last_cursor when closing the last window for the buffer. |
532 * Remember the last cursor position and window options of the buffer. | 527 * Remember the last cursor position and window options of the buffer. |
533 * This used to be only for the current window, but then options like | 528 * This used to be only for the current window, but then options like |
534 * 'foldmethod' may be lost with a ":only" command. */ | 529 * 'foldmethod' may be lost with a ":only" command. */ |
579 if (aborting()) /* autocmds may abort script processing */ | 574 if (aborting()) /* autocmds may abort script processing */ |
580 return; | 575 return; |
581 # endif | 576 # endif |
582 } | 577 } |
583 | 578 |
584 # ifdef FEAT_WINDOWS | |
585 /* If the buffer was in curwin and the window has changed, go back to that | 579 /* If the buffer was in curwin and the window has changed, go back to that |
586 * window, if it still exists. This avoids that ":edit x" triggering a | 580 * window, if it still exists. This avoids that ":edit x" triggering a |
587 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ | 581 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ |
588 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) | 582 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) |
589 { | 583 { |
590 block_autocmds(); | 584 block_autocmds(); |
591 goto_tabpage_win(the_curtab, the_curwin); | 585 goto_tabpage_win(the_curtab, the_curwin); |
592 unblock_autocmds(); | 586 unblock_autocmds(); |
593 } | 587 } |
594 # endif | |
595 | 588 |
596 nwindows = buf->b_nwindows; | 589 nwindows = buf->b_nwindows; |
597 #endif | 590 #endif |
598 | 591 |
599 /* decrease the link count from windows (unless not in any window) */ | 592 /* decrease the link count from windows (unless not in any window) */ |
648 * deleted buffer. | 641 * deleted buffer. |
649 */ | 642 */ |
650 if (buf == curbuf && !is_curbuf) | 643 if (buf == curbuf && !is_curbuf) |
651 return; | 644 return; |
652 | 645 |
653 if ( | 646 if (win_valid_any_tab(win) && win->w_buffer == buf) |
654 #ifdef FEAT_WINDOWS | |
655 win_valid_any_tab(win) && | |
656 #else | |
657 win != NULL && | |
658 #endif | |
659 win->w_buffer == buf) | |
660 win->w_buffer = NULL; /* make sure we don't use the buffer now */ | 647 win->w_buffer = NULL; /* make sure we don't use the buffer now */ |
661 | 648 |
662 /* Autocommands may have opened or closed windows for this buffer. | 649 /* Autocommands may have opened or closed windows for this buffer. |
663 * Decrement the count for the close we do here. */ | 650 * Decrement the count for the close we do here. */ |
664 if (buf->b_nwindows > 0) | 651 if (buf->b_nwindows > 0) |
744 buf_freeall(buf_T *buf, int flags) | 731 buf_freeall(buf_T *buf, int flags) |
745 { | 732 { |
746 #ifdef FEAT_AUTOCMD | 733 #ifdef FEAT_AUTOCMD |
747 int is_curbuf = (buf == curbuf); | 734 int is_curbuf = (buf == curbuf); |
748 bufref_T bufref; | 735 bufref_T bufref; |
749 # ifdef FEAT_WINDOWS | |
750 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); | 736 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
751 win_T *the_curwin = curwin; | 737 win_T *the_curwin = curwin; |
752 tabpage_T *the_curtab = curtab; | 738 tabpage_T *the_curtab = curtab; |
753 # endif | |
754 | 739 |
755 /* Make sure the buffer isn't closed by autocommands. */ | 740 /* Make sure the buffer isn't closed by autocommands. */ |
756 ++buf->b_locked; | 741 ++buf->b_locked; |
757 set_bufref(&bufref, buf); | 742 set_bufref(&bufref, buf); |
758 if (buf->b_ml.ml_mfp != NULL) | 743 if (buf->b_ml.ml_mfp != NULL) |
779 /* autocommands deleted the buffer */ | 764 /* autocommands deleted the buffer */ |
780 return; | 765 return; |
781 } | 766 } |
782 --buf->b_locked; | 767 --buf->b_locked; |
783 | 768 |
784 # ifdef FEAT_WINDOWS | |
785 /* If the buffer was in curwin and the window has changed, go back to that | 769 /* If the buffer was in curwin and the window has changed, go back to that |
786 * window, if it still exists. This avoids that ":edit x" triggering a | 770 * window, if it still exists. This avoids that ":edit x" triggering a |
787 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ | 771 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ |
788 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) | 772 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin)) |
789 { | 773 { |
790 block_autocmds(); | 774 block_autocmds(); |
791 goto_tabpage_win(the_curtab, the_curwin); | 775 goto_tabpage_win(the_curtab, the_curwin); |
792 unblock_autocmds(); | 776 unblock_autocmds(); |
793 } | 777 } |
794 # endif | |
795 | 778 |
796 # ifdef FEAT_EVAL | 779 # ifdef FEAT_EVAL |
797 if (aborting()) /* autocmds may abort script processing */ | 780 if (aborting()) /* autocmds may abort script processing */ |
798 return; | 781 return; |
799 # endif | 782 # endif |
816 reset_synblock(curwin); | 799 reset_synblock(curwin); |
817 #endif | 800 #endif |
818 | 801 |
819 #ifdef FEAT_FOLDING | 802 #ifdef FEAT_FOLDING |
820 /* No folds in an empty buffer. */ | 803 /* No folds in an empty buffer. */ |
821 # ifdef FEAT_WINDOWS | |
822 { | 804 { |
823 win_T *win; | 805 win_T *win; |
824 tabpage_T *tp; | 806 tabpage_T *tp; |
825 | 807 |
826 FOR_ALL_TAB_WINDOWS(tp, win) | 808 FOR_ALL_TAB_WINDOWS(tp, win) |
827 if (win->w_buffer == buf) | 809 if (win->w_buffer == buf) |
828 clearFolding(win); | 810 clearFolding(win); |
829 } | 811 } |
830 # else | |
831 if (curwin != NULL && curwin->w_buffer == buf) | |
832 clearFolding(curwin); | |
833 # endif | |
834 #endif | 812 #endif |
835 | 813 |
836 #ifdef FEAT_TCL | 814 #ifdef FEAT_TCL |
837 tcl_buffer_free(buf); | 815 tcl_buffer_free(buf); |
838 #endif | 816 #endif |
999 exarg_T *eap, | 977 exarg_T *eap, |
1000 int start, | 978 int start, |
1001 int dir, | 979 int dir, |
1002 int count) | 980 int count) |
1003 { | 981 { |
1004 # if defined(FEAT_WINDOWS) && defined(HAS_SWAP_EXISTS_ACTION) | 982 # if defined(HAS_SWAP_EXISTS_ACTION) |
1005 bufref_T old_curbuf; | 983 bufref_T old_curbuf; |
1006 | 984 |
1007 set_bufref(&old_curbuf, curbuf); | 985 set_bufref(&old_curbuf, curbuf); |
1008 | 986 |
1009 swap_exists_action = SEA_DIALOG; | 987 swap_exists_action = SEA_DIALOG; |
1010 # endif | 988 # endif |
1011 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | 989 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, |
1012 start, dir, count, eap->forceit); | 990 start, dir, count, eap->forceit); |
1013 # if defined(FEAT_WINDOWS) && defined(HAS_SWAP_EXISTS_ACTION) | 991 # if defined(HAS_SWAP_EXISTS_ACTION) |
1014 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') | 992 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') |
1015 { | 993 { |
1016 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 994 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
1017 cleanup_T cs; | 995 cleanup_T cs; |
1018 | 996 |
1267 EMSG(_("E90: Cannot unload last buffer")); | 1245 EMSG(_("E90: Cannot unload last buffer")); |
1268 return FAIL; | 1246 return FAIL; |
1269 } | 1247 } |
1270 | 1248 |
1271 set_bufref(&bufref, buf); | 1249 set_bufref(&bufref, buf); |
1272 #ifdef FEAT_WINDOWS | |
1273 if (close_others) | 1250 if (close_others) |
1274 /* Close any other windows on this buffer, then make it empty. */ | 1251 /* Close any other windows on this buffer, then make it empty. */ |
1275 close_windows(buf, TRUE); | 1252 close_windows(buf, TRUE); |
1276 #endif | |
1277 | 1253 |
1278 setpcmark(); | 1254 setpcmark(); |
1279 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, | 1255 retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE, |
1280 forceit ? ECMD_FORCEIT : 0, curwin); | 1256 forceit ? ECMD_FORCEIT : 0, curwin); |
1281 | 1257 |
1408 * delete buffer buf from memory and/or the list | 1384 * delete buffer buf from memory and/or the list |
1409 */ | 1385 */ |
1410 if (unload) | 1386 if (unload) |
1411 { | 1387 { |
1412 int forward; | 1388 int forward; |
1413 # if defined(FEAT_AUTOCMD) || defined(FEAT_WINDOWS) | |
1414 bufref_T bufref; | 1389 bufref_T bufref; |
1415 | 1390 |
1416 set_bufref(&bufref, buf); | 1391 set_bufref(&bufref, buf); |
1417 # endif | |
1418 | 1392 |
1419 /* When unloading or deleting a buffer that's already unloaded and | 1393 /* When unloading or deleting a buffer that's already unloaded and |
1420 * unlisted: fail silently. */ | 1394 * unlisted: fail silently. */ |
1421 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) | 1395 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) |
1422 return FAIL; | 1396 return FAIL; |
1459 if (bp->b_p_bl && bp != buf) | 1433 if (bp->b_p_bl && bp != buf) |
1460 break; | 1434 break; |
1461 if (bp == NULL && buf == curbuf) | 1435 if (bp == NULL && buf == curbuf) |
1462 return empty_curbuf(TRUE, forceit, action); | 1436 return empty_curbuf(TRUE, forceit, action); |
1463 | 1437 |
1464 #ifdef FEAT_WINDOWS | |
1465 /* | 1438 /* |
1466 * If the deleted buffer is the current one, close the current window | 1439 * If the deleted buffer is the current one, close the current window |
1467 * (unless it's the only window). Repeat this so long as we end up in | 1440 * (unless it's the only window). Repeat this so long as we end up in |
1468 * a window with this buffer. | 1441 * a window with this buffer. |
1469 */ | 1442 */ |
1470 while (buf == curbuf | 1443 while (buf == curbuf |
1471 # ifdef FEAT_AUTOCMD | 1444 #ifdef FEAT_AUTOCMD |
1472 && !(curwin->w_closing || curwin->w_buffer->b_locked > 0) | 1445 && !(curwin->w_closing || curwin->w_buffer->b_locked > 0) |
1473 # endif | 1446 #endif |
1474 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) | 1447 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) |
1475 { | 1448 { |
1476 if (win_close(curwin, FALSE) == FAIL) | 1449 if (win_close(curwin, FALSE) == FAIL) |
1477 break; | 1450 break; |
1478 } | 1451 } |
1479 #endif | |
1480 | 1452 |
1481 /* | 1453 /* |
1482 * If the buffer to be deleted is not the current one, delete it here. | 1454 * If the buffer to be deleted is not the current one, delete it here. |
1483 */ | 1455 */ |
1484 if (buf != curbuf) | 1456 if (buf != curbuf) |
1485 { | 1457 { |
1486 #ifdef FEAT_WINDOWS | |
1487 close_windows(buf, FALSE); | 1458 close_windows(buf, FALSE); |
1488 if (buf != curbuf && bufref_valid(&bufref)) | 1459 if (buf != curbuf && bufref_valid(&bufref) && buf->b_nwindows <= 0) |
1489 #endif | |
1490 if (buf->b_nwindows <= 0) | |
1491 close_buffer(NULL, buf, action, FALSE); | 1460 close_buffer(NULL, buf, action, FALSE); |
1492 return OK; | 1461 return OK; |
1493 } | 1462 } |
1494 | 1463 |
1495 /* | 1464 /* |
1604 /* | 1573 /* |
1605 * make buf current buffer | 1574 * make buf current buffer |
1606 */ | 1575 */ |
1607 if (action == DOBUF_SPLIT) /* split window first */ | 1576 if (action == DOBUF_SPLIT) /* split window first */ |
1608 { | 1577 { |
1609 # ifdef FEAT_WINDOWS | |
1610 /* If 'switchbuf' contains "useopen": jump to first window containing | 1578 /* If 'switchbuf' contains "useopen": jump to first window containing |
1611 * "buf" if one exists */ | 1579 * "buf" if one exists */ |
1612 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) | 1580 if ((swb_flags & SWB_USEOPEN) && buf_jump_open_win(buf)) |
1613 return OK; | 1581 return OK; |
1614 /* If 'switchbuf' contains "usetab": jump to first window in any tab | 1582 /* If 'switchbuf' contains "usetab": jump to first window in any tab |
1615 * page containing "buf" if one exists */ | 1583 * page containing "buf" if one exists */ |
1616 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) | 1584 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) |
1617 return OK; | 1585 return OK; |
1618 if (win_split(0, 0) == FAIL) | 1586 if (win_split(0, 0) == FAIL) |
1619 # endif | |
1620 return FAIL; | 1587 return FAIL; |
1621 } | 1588 } |
1622 #endif | 1589 #endif |
1623 | 1590 |
1624 /* go to current buffer - nothing to do */ | 1591 /* go to current buffer - nothing to do */ |
1717 { | 1684 { |
1718 #ifdef FEAT_SYN_HL | 1685 #ifdef FEAT_SYN_HL |
1719 if (prevbuf == curwin->w_buffer) | 1686 if (prevbuf == curwin->w_buffer) |
1720 reset_synblock(curwin); | 1687 reset_synblock(curwin); |
1721 #endif | 1688 #endif |
1722 #ifdef FEAT_WINDOWS | |
1723 if (unload) | 1689 if (unload) |
1724 close_windows(prevbuf, FALSE); | 1690 close_windows(prevbuf, FALSE); |
1725 #endif | |
1726 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1691 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) |
1727 if (bufref_valid(&bufref) && !aborting()) | 1692 if (bufref_valid(&bufref) && !aborting()) |
1728 #else | 1693 #else |
1729 if (bufref_valid(&bufref)) | 1694 if (bufref_valid(&bufref)) |
1730 #endif | 1695 #endif |
1731 { | 1696 { |
1732 #ifdef FEAT_WINDOWS | |
1733 win_T *previouswin = curwin; | 1697 win_T *previouswin = curwin; |
1734 #endif | |
1735 if (prevbuf == curbuf) | 1698 if (prevbuf == curbuf) |
1736 u_sync(FALSE); | 1699 u_sync(FALSE); |
1737 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, | 1700 close_buffer(prevbuf == curwin->w_buffer ? curwin : NULL, prevbuf, |
1738 unload ? action : (action == DOBUF_GOTO | 1701 unload ? action : (action == DOBUF_GOTO |
1739 && !buf_hide(prevbuf) | 1702 && !buf_hide(prevbuf) |
1740 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); | 1703 && !bufIsChanged(prevbuf)) ? DOBUF_UNLOAD : 0, FALSE); |
1741 #ifdef FEAT_WINDOWS | |
1742 if (curwin != previouswin && win_valid(previouswin)) | 1704 if (curwin != previouswin && win_valid(previouswin)) |
1743 /* autocommands changed curwin, Grr! */ | 1705 /* autocommands changed curwin, Grr! */ |
1744 curwin = previouswin; | 1706 curwin = previouswin; |
1745 #endif | |
1746 } | 1707 } |
1747 } | 1708 } |
1748 #ifdef FEAT_AUTOCMD | 1709 #ifdef FEAT_AUTOCMD |
1749 /* An autocommand may have deleted "buf", already entered it (e.g., when | 1710 /* An autocommand may have deleted "buf", already entered it (e.g., when |
1750 * it did ":bunload") or aborted the script processing. | 1711 * it did ":bunload") or aborted the script processing. |
1751 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ | 1712 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ |
1752 if ((buf_valid(buf) && buf != curbuf | 1713 if ((buf_valid(buf) && buf != curbuf |
1753 # ifdef FEAT_EVAL | 1714 # ifdef FEAT_EVAL |
1754 && !aborting() | 1715 && !aborting() |
1755 # endif | 1716 # endif |
1756 # ifdef FEAT_WINDOWS | 1717 ) || curwin->w_buffer == NULL) |
1757 ) || curwin->w_buffer == NULL | |
1758 # endif | |
1759 ) | |
1760 #endif | 1718 #endif |
1761 { | 1719 { |
1762 enter_buffer(buf); | 1720 enter_buffer(buf); |
1763 #ifdef FEAT_SYN_HL | 1721 #ifdef FEAT_SYN_HL |
1764 if (old_tw != curbuf->b_p_tw) | 1722 if (old_tw != curbuf->b_p_tw) |
2325 linenr_T lnum, | 2283 linenr_T lnum, |
2326 int options, | 2284 int options, |
2327 int forceit) | 2285 int forceit) |
2328 { | 2286 { |
2329 buf_T *buf; | 2287 buf_T *buf; |
2330 #ifdef FEAT_WINDOWS | |
2331 win_T *wp = NULL; | 2288 win_T *wp = NULL; |
2332 #endif | |
2333 pos_T *fpos; | 2289 pos_T *fpos; |
2334 colnr_T col; | 2290 colnr_T col; |
2335 | 2291 |
2336 buf = buflist_findnr(n); | 2292 buf = buflist_findnr(n); |
2337 if (buf == NULL) | 2293 if (buf == NULL) |
2365 col = fpos->col; | 2321 col = fpos->col; |
2366 } | 2322 } |
2367 else | 2323 else |
2368 col = 0; | 2324 col = 0; |
2369 | 2325 |
2370 #ifdef FEAT_WINDOWS | |
2371 if (options & GETF_SWITCH) | 2326 if (options & GETF_SWITCH) |
2372 { | 2327 { |
2373 /* If 'switchbuf' contains "useopen": jump to first window containing | 2328 /* If 'switchbuf' contains "useopen": jump to first window containing |
2374 * "buf" if one exists */ | 2329 * "buf" if one exists */ |
2375 if (swb_flags & SWB_USEOPEN) | 2330 if (swb_flags & SWB_USEOPEN) |
2391 == FAIL) | 2346 == FAIL) |
2392 return FAIL; | 2347 return FAIL; |
2393 RESET_BINDING(curwin); | 2348 RESET_BINDING(curwin); |
2394 } | 2349 } |
2395 } | 2350 } |
2396 #endif | |
2397 | 2351 |
2398 ++RedrawingDisabled; | 2352 ++RedrawingDisabled; |
2399 if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL, | 2353 if (GETFILE_SUCCESS(getfile(buf->b_fnum, NULL, NULL, |
2400 (options & GETF_SETMARK), lnum, forceit))) | 2354 (options & GETF_SETMARK), lnum, forceit))) |
2401 { | 2355 { |
2596 { | 2550 { |
2597 if (curtab_only) | 2551 if (curtab_only) |
2598 { | 2552 { |
2599 /* Ignore the match if the buffer is not open in | 2553 /* Ignore the match if the buffer is not open in |
2600 * the current tab. */ | 2554 * the current tab. */ |
2601 #ifdef FEAT_WINDOWS | |
2602 win_T *wp; | 2555 win_T *wp; |
2603 | 2556 |
2604 FOR_ALL_WINDOWS(wp) | 2557 FOR_ALL_WINDOWS(wp) |
2605 if (wp->w_buffer == buf) | 2558 if (wp->w_buffer == buf) |
2606 break; | 2559 break; |
2607 if (wp == NULL) | 2560 if (wp == NULL) |
2608 continue; | 2561 continue; |
2609 #else | |
2610 if (curwin->w_buffer != buf) | |
2611 continue; | |
2612 #endif | |
2613 } | 2562 } |
2614 if (match >= 0) /* already found a match */ | 2563 if (match >= 0) /* already found a match */ |
2615 { | 2564 { |
2616 match = -2; | 2565 match = -2; |
2617 break; | 2566 break; |
3087 changed_char = (buf->b_flags & BF_READERR) ? 'x' | 3036 changed_char = (buf->b_flags & BF_READERR) ? 'x' |
3088 : (bufIsChanged(buf) ? '+' : ' '); | 3037 : (bufIsChanged(buf) ? '+' : ' '); |
3089 #ifdef FEAT_TERMINAL | 3038 #ifdef FEAT_TERMINAL |
3090 if (term_job_running(buf->b_term)) | 3039 if (term_job_running(buf->b_term)) |
3091 { | 3040 { |
3092 ro_char = 'R'; | 3041 if (term_none_open(buf->b_term)) |
3042 ro_char = '?'; | |
3043 else | |
3044 ro_char = 'R'; | |
3093 changed_char = ' '; /* bufIsChanged() returns TRUE to avoid | 3045 changed_char = ' '; /* bufIsChanged() returns TRUE to avoid |
3094 * closing, but it's not actually changed. */ | 3046 * closing, but it's not actually changed. */ |
3095 } | 3047 } |
3096 else if (buf->b_term != NULL) | 3048 else if (buf->b_term != NULL) |
3097 ro_char = 'F'; | 3049 ro_char = 'F'; |
3290 if (curwin->w_buffer == buf) | 3242 if (curwin->w_buffer == buf) |
3291 check_arg_idx(curwin); /* check file name for arg list */ | 3243 check_arg_idx(curwin); /* check file name for arg list */ |
3292 #ifdef FEAT_TITLE | 3244 #ifdef FEAT_TITLE |
3293 maketitle(); /* set window title */ | 3245 maketitle(); /* set window title */ |
3294 #endif | 3246 #endif |
3295 #ifdef FEAT_WINDOWS | |
3296 status_redraw_all(); /* status lines need to be redrawn */ | 3247 status_redraw_all(); /* status lines need to be redrawn */ |
3297 #endif | |
3298 fmarks_check_names(buf); /* check named file marks */ | 3248 fmarks_check_names(buf); /* check named file marks */ |
3299 ml_timestamp(buf); /* reset timestamp */ | 3249 ml_timestamp(buf); /* reset timestamp */ |
3300 } | 3250 } |
3301 | 3251 |
3302 /* | 3252 /* |
4420 str = tmp; | 4370 str = tmp; |
4421 } | 4371 } |
4422 break; | 4372 break; |
4423 #endif | 4373 #endif |
4424 | 4374 |
4425 #if defined(FEAT_WINDOWS) && defined(FEAT_QUICKFIX) | 4375 #if defined(FEAT_QUICKFIX) |
4426 case STL_PREVIEWFLAG: | 4376 case STL_PREVIEWFLAG: |
4427 case STL_PREVIEWFLAG_ALT: | 4377 case STL_PREVIEWFLAG_ALT: |
4428 itemisflag = TRUE; | 4378 itemisflag = TRUE; |
4429 if (wp->w_p_pvw) | 4379 if (wp->w_p_pvw) |
4430 str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" | 4380 str = (char_u *)((opt == STL_PREVIEWFLAG_ALT) ? ",PRV" |
4906 if (bp == NULL || bp->b_fname == NULL) | 4856 if (bp == NULL || bp->b_fname == NULL) |
4907 return aep->ae_fname; | 4857 return aep->ae_fname; |
4908 return bp->b_fname; | 4858 return bp->b_fname; |
4909 } | 4859 } |
4910 | 4860 |
4911 #if defined(FEAT_WINDOWS) || defined(PROTO) | |
4912 /* | 4861 /* |
4913 * do_arg_all(): Open up to 'count' windows, one for each argument. | 4862 * do_arg_all(): Open up to 'count' windows, one for each argument. |
4914 */ | 4863 */ |
4915 void | 4864 void |
4916 do_arg_all( | 4865 do_arg_all( |
5055 wpnext = firstwin; /* start all over... */ | 5004 wpnext = firstwin; /* start all over... */ |
5056 continue; | 5005 continue; |
5057 } | 5006 } |
5058 #endif | 5007 #endif |
5059 } | 5008 } |
5060 #ifdef FEAT_WINDOWS | |
5061 /* don't close last window */ | 5009 /* don't close last window */ |
5062 if (ONE_WINDOW | 5010 if (ONE_WINDOW |
5063 && (first_tabpage->tp_next == NULL || !had_tab)) | 5011 && (first_tabpage->tp_next == NULL || !had_tab)) |
5064 #endif | |
5065 use_firstwin = TRUE; | 5012 use_firstwin = TRUE; |
5066 #ifdef FEAT_WINDOWS | |
5067 else | 5013 else |
5068 { | 5014 { |
5069 win_close(wp, !buf_hide(buf) && !bufIsChanged(buf)); | 5015 win_close(wp, !buf_hide(buf) && !bufIsChanged(buf)); |
5070 # ifdef FEAT_AUTOCMD | 5016 #ifdef FEAT_AUTOCMD |
5071 /* check if autocommands removed the next window */ | 5017 /* check if autocommands removed the next window */ |
5072 if (!win_valid(wpnext)) | 5018 if (!win_valid(wpnext)) |
5073 wpnext = firstwin; /* start all over... */ | 5019 wpnext = firstwin; /* start all over... */ |
5074 # endif | 5020 #endif |
5075 } | 5021 } |
5076 #endif | |
5077 } | 5022 } |
5078 } | 5023 } |
5079 } | 5024 } |
5080 | 5025 |
5081 /* Without the ":tab" modifier only do the current tab page. */ | 5026 /* Without the ":tab" modifier only do the current tab page. */ |
5103 ++autocmd_no_leave; | 5048 ++autocmd_no_leave; |
5104 #endif | 5049 #endif |
5105 last_curwin = curwin; | 5050 last_curwin = curwin; |
5106 last_curtab = curtab; | 5051 last_curtab = curtab; |
5107 win_enter(lastwin, FALSE); | 5052 win_enter(lastwin, FALSE); |
5108 #ifdef FEAT_WINDOWS | |
5109 /* ":drop all" should re-use an empty window to avoid "--remote-tab" | 5053 /* ":drop all" should re-use an empty window to avoid "--remote-tab" |
5110 * leaving an empty tab page when executed locally. */ | 5054 * leaving an empty tab page when executed locally. */ |
5111 if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1 | 5055 if (keep_tabs && BUFEMPTY() && curbuf->b_nwindows == 1 |
5112 && curbuf->b_ffname == NULL && !curbuf->b_changed) | 5056 && curbuf->b_ffname == NULL && !curbuf->b_changed) |
5113 use_firstwin = TRUE; | 5057 use_firstwin = TRUE; |
5114 #endif | |
5115 | 5058 |
5116 for (i = 0; i < count && i < opened_len && !got_int; ++i) | 5059 for (i = 0; i < count && i < opened_len && !got_int; ++i) |
5117 { | 5060 { |
5118 if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1) | 5061 if (alist == &global_alist && i == global_alist.al_ga.ga_len - 1) |
5119 arg_had_last = TRUE; | 5062 arg_had_last = TRUE; |
5220 int p_ea_save; | 5163 int p_ea_save; |
5221 int open_wins = 0; | 5164 int open_wins = 0; |
5222 int r; | 5165 int r; |
5223 int count; /* Maximum number of windows to open. */ | 5166 int count; /* Maximum number of windows to open. */ |
5224 int all; /* When TRUE also load inactive buffers. */ | 5167 int all; /* When TRUE also load inactive buffers. */ |
5225 #ifdef FEAT_WINDOWS | |
5226 int had_tab = cmdmod.tab; | 5168 int had_tab = cmdmod.tab; |
5227 tabpage_T *tpnext; | 5169 tabpage_T *tpnext; |
5228 #endif | |
5229 | 5170 |
5230 if (eap->addr_count == 0) /* make as many windows as possible */ | 5171 if (eap->addr_count == 0) /* make as many windows as possible */ |
5231 count = 9999; | 5172 count = 9999; |
5232 else | 5173 else |
5233 count = eap->line2; /* make as many windows as specified */ | 5174 count = eap->line2; /* make as many windows as specified */ |
5244 | 5185 |
5245 /* | 5186 /* |
5246 * Close superfluous windows (two windows for the same buffer). | 5187 * Close superfluous windows (two windows for the same buffer). |
5247 * Also close windows that are not full-width. | 5188 * Also close windows that are not full-width. |
5248 */ | 5189 */ |
5249 #ifdef FEAT_WINDOWS | |
5250 if (had_tab > 0) | 5190 if (had_tab > 0) |
5251 goto_tabpage_tp(first_tabpage, TRUE, TRUE); | 5191 goto_tabpage_tp(first_tabpage, TRUE, TRUE); |
5252 for (;;) | 5192 for (;;) |
5253 { | 5193 { |
5254 #endif | |
5255 tpnext = curtab->tp_next; | 5194 tpnext = curtab->tp_next; |
5256 for (wp = firstwin; wp != NULL; wp = wpnext) | 5195 for (wp = firstwin; wp != NULL; wp = wpnext) |
5257 { | 5196 { |
5258 wpnext = wp->w_next; | 5197 wpnext = wp->w_next; |
5259 if ((wp->w_buffer->b_nwindows > 1 | 5198 if ((wp->w_buffer->b_nwindows > 1 |
5260 #ifdef FEAT_WINDOWS | |
5261 || ((cmdmod.split & WSP_VERT) | 5199 || ((cmdmod.split & WSP_VERT) |
5262 ? wp->w_height + wp->w_status_height < Rows - p_ch | 5200 ? wp->w_height + wp->w_status_height < Rows - p_ch |
5263 - tabline_height() | 5201 - tabline_height() |
5264 : wp->w_width != Columns) | 5202 : wp->w_width != Columns) |
5265 || (had_tab > 0 && wp != firstwin) | 5203 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW |
5266 #endif | |
5267 ) && !ONE_WINDOW | |
5268 #ifdef FEAT_AUTOCMD | 5204 #ifdef FEAT_AUTOCMD |
5269 && !(wp->w_closing || wp->w_buffer->b_locked > 0) | 5205 && !(wp->w_closing || wp->w_buffer->b_locked > 0) |
5270 #endif | 5206 #endif |
5271 ) | 5207 ) |
5272 { | 5208 { |
5280 } | 5216 } |
5281 else | 5217 else |
5282 ++open_wins; | 5218 ++open_wins; |
5283 } | 5219 } |
5284 | 5220 |
5285 #ifdef FEAT_WINDOWS | |
5286 /* Without the ":tab" modifier only do the current tab page. */ | 5221 /* Without the ":tab" modifier only do the current tab page. */ |
5287 if (had_tab == 0 || tpnext == NULL) | 5222 if (had_tab == 0 || tpnext == NULL) |
5288 break; | 5223 break; |
5289 goto_tabpage_tp(tpnext, TRUE, TRUE); | 5224 goto_tabpage_tp(tpnext, TRUE, TRUE); |
5290 } | 5225 } |
5291 #endif | |
5292 | 5226 |
5293 /* | 5227 /* |
5294 * Go through the buffer list. When a buffer doesn't have a window yet, | 5228 * Go through the buffer list. When a buffer doesn't have a window yet, |
5295 * open one. Otherwise move the window to the right position. | 5229 * open one. Otherwise move the window to the right position. |
5296 * Watch out for autocommands that delete buffers or windows! | 5230 * Watch out for autocommands that delete buffers or windows! |
5307 { | 5241 { |
5308 /* Check if this buffer needs a window */ | 5242 /* Check if this buffer needs a window */ |
5309 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) | 5243 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) |
5310 continue; | 5244 continue; |
5311 | 5245 |
5312 #ifdef FEAT_WINDOWS | |
5313 if (had_tab != 0) | 5246 if (had_tab != 0) |
5314 { | 5247 { |
5315 /* With the ":tab" modifier don't move the window. */ | 5248 /* With the ":tab" modifier don't move the window. */ |
5316 if (buf->b_nwindows > 0) | 5249 if (buf->b_nwindows > 0) |
5317 wp = lastwin; /* buffer has a window, skip it */ | 5250 wp = lastwin; /* buffer has a window, skip it */ |
5318 else | 5251 else |
5319 wp = NULL; | 5252 wp = NULL; |
5320 } | 5253 } |
5321 else | 5254 else |
5322 #endif | |
5323 { | 5255 { |
5324 /* Check if this buffer already has a window */ | 5256 /* Check if this buffer already has a window */ |
5325 FOR_ALL_WINDOWS(wp) | 5257 FOR_ALL_WINDOWS(wp) |
5326 if (wp->w_buffer == buf) | 5258 if (wp->w_buffer == buf) |
5327 break; | 5259 break; |
5399 #ifdef FEAT_EVAL | 5331 #ifdef FEAT_EVAL |
5400 /* Autocommands deleted the buffer or aborted script processing!!! */ | 5332 /* Autocommands deleted the buffer or aborted script processing!!! */ |
5401 if (aborting()) | 5333 if (aborting()) |
5402 break; | 5334 break; |
5403 #endif | 5335 #endif |
5404 #ifdef FEAT_WINDOWS | |
5405 /* When ":tab" was used open a new tab for a new window repeatedly. */ | 5336 /* When ":tab" was used open a new tab for a new window repeatedly. */ |
5406 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) | 5337 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) |
5407 cmdmod.tab = 9999; | 5338 cmdmod.tab = 9999; |
5408 #endif | |
5409 } | 5339 } |
5410 #ifdef FEAT_AUTOCMD | 5340 #ifdef FEAT_AUTOCMD |
5411 --autocmd_no_enter; | 5341 --autocmd_no_enter; |
5412 #endif | 5342 #endif |
5413 win_enter(firstwin, FALSE); /* back to first window */ | 5343 win_enter(firstwin, FALSE); /* back to first window */ |
5444 } | 5374 } |
5445 } | 5375 } |
5446 } | 5376 } |
5447 # endif /* FEAT_LISTCMDS */ | 5377 # endif /* FEAT_LISTCMDS */ |
5448 | 5378 |
5449 #endif /* FEAT_WINDOWS */ | |
5450 | 5379 |
5451 static int chk_modeline(linenr_T, int); | 5380 static int chk_modeline(linenr_T, int); |
5452 | 5381 |
5453 /* | 5382 /* |
5454 * do_modelines() - process mode lines for the current file | 5383 * do_modelines() - process mode lines for the current file |
5671 | 5600 |
5672 void | 5601 void |
5673 write_viminfo_bufferlist(FILE *fp) | 5602 write_viminfo_bufferlist(FILE *fp) |
5674 { | 5603 { |
5675 buf_T *buf; | 5604 buf_T *buf; |
5676 #ifdef FEAT_WINDOWS | |
5677 win_T *win; | 5605 win_T *win; |
5678 tabpage_T *tp; | 5606 tabpage_T *tp; |
5679 #endif | |
5680 char_u *line; | 5607 char_u *line; |
5681 int max_buffers; | 5608 int max_buffers; |
5682 | 5609 |
5683 if (find_viminfo_parameter('%') == NULL) | 5610 if (find_viminfo_parameter('%') == NULL) |
5684 return; | 5611 return; |
5690 #define LINE_BUF_LEN (MAXPATHL + 40) | 5617 #define LINE_BUF_LEN (MAXPATHL + 40) |
5691 line = alloc(LINE_BUF_LEN); | 5618 line = alloc(LINE_BUF_LEN); |
5692 if (line == NULL) | 5619 if (line == NULL) |
5693 return; | 5620 return; |
5694 | 5621 |
5695 #ifdef FEAT_WINDOWS | |
5696 FOR_ALL_TAB_WINDOWS(tp, win) | 5622 FOR_ALL_TAB_WINDOWS(tp, win) |
5697 set_last_cursor(win); | 5623 set_last_cursor(win); |
5698 #else | |
5699 set_last_cursor(curwin); | |
5700 #endif | |
5701 | 5624 |
5702 fputs(_("\n# Buffer list:\n"), fp); | 5625 fputs(_("\n# Buffer list:\n"), fp); |
5703 FOR_ALL_BUFFERS(buf) | 5626 FOR_ALL_BUFFERS(buf) |
5704 { | 5627 { |
5705 if (buf->b_fname == NULL | 5628 if (buf->b_fname == NULL |
5808 * Returns NULL when the buffer has a normal file name. | 5731 * Returns NULL when the buffer has a normal file name. |
5809 */ | 5732 */ |
5810 char_u * | 5733 char_u * |
5811 buf_spname(buf_T *buf) | 5734 buf_spname(buf_T *buf) |
5812 { | 5735 { |
5813 #if defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS) | 5736 #if defined(FEAT_QUICKFIX) |
5814 if (bt_quickfix(buf)) | 5737 if (bt_quickfix(buf)) |
5815 { | 5738 { |
5816 win_T *win; | 5739 win_T *win; |
5817 tabpage_T *tp; | 5740 tabpage_T *tp; |
5818 | 5741 |
5886 else | 5809 else |
5887 restore_buffer(save_curbuf); | 5810 restore_buffer(save_curbuf); |
5888 } | 5811 } |
5889 #endif | 5812 #endif |
5890 | 5813 |
5891 #if (defined(FEAT_QUICKFIX) && defined(FEAT_WINDOWS)) \ | 5814 #if defined(FEAT_QUICKFIX) || defined(SWITCH_TO_WIN) || defined(PROTO) |
5892 || defined(SWITCH_TO_WIN) \ | |
5893 || defined(PROTO) | |
5894 /* | 5815 /* |
5895 * Find a window for buffer "buf". | 5816 * Find a window for buffer "buf". |
5896 * If found OK is returned and "wp" and "tp" are set to the window and tabpage. | 5817 * If found OK is returned and "wp" and "tp" are set to the window and tabpage. |
5897 * If not found FAIL is returned. | 5818 * If not found FAIL is returned. |
5898 */ | 5819 */ |