Mercurial > vim
comparison src/buffer.c @ 13553:04019fc3de93 v8.0.1650
patch 8.0.1650: too many #ifdefs
commit https://github.com/vim/vim/commit/0c72fe4ed8430db41f43c5878e6ee60265dc49e9
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Mar 29 16:04:08 2018 +0200
patch 8.0.1650: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate FEAT_LISTCMDS, no reason to leave out buffer commands.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 29 Mar 2018 16:15:07 +0200 |
parents | e9ffb5b35266 |
children | 78ead137b2ad |
comparison
equal
deleted
inserted
replaced
13552:5417164ac275 | 13553:04019fc3de93 |
---|---|
25 * The current implementation remembers all file names ever used. | 25 * The current implementation remembers all file names ever used. |
26 */ | 26 */ |
27 | 27 |
28 #include "vim.h" | 28 #include "vim.h" |
29 | 29 |
30 #if defined(FEAT_CMDL_COMPL) || defined(FEAT_LISTCMDS) || defined(FEAT_EVAL) || defined(FEAT_PERL) | |
31 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); | 30 static char_u *buflist_match(regmatch_T *rmp, buf_T *buf, int ignore_case); |
32 # define HAVE_BUFLIST_MATCH | |
33 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); | 31 static char_u *fname_match(regmatch_T *rmp, char_u *name, int ignore_case); |
34 #endif | |
35 static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options); | 32 static void buflist_setfpos(buf_T *buf, win_T *win, linenr_T lnum, colnr_T col, int copy_options); |
36 static wininfo_T *find_wininfo(buf_T *buf, int skip_diff_buffer); | |
37 #ifdef UNIX | 33 #ifdef UNIX |
38 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); | 34 static buf_T *buflist_findname_stat(char_u *ffname, stat_T *st); |
39 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); | 35 static int otherfile_buf(buf_T *buf, char_u *ffname, stat_T *stp); |
40 static int buf_same_ino(buf_T *buf, stat_T *stp); | 36 static int buf_same_ino(buf_T *buf, stat_T *stp); |
41 #else | 37 #else |
946 } | 942 } |
947 vim_free(wip); | 943 vim_free(wip); |
948 } | 944 } |
949 } | 945 } |
950 | 946 |
951 #if defined(FEAT_LISTCMDS) || defined(FEAT_TERMINAL) || defined(PROTO) | |
952 /* | 947 /* |
953 * Go to another buffer. Handles the result of the ATTENTION dialog. | 948 * Go to another buffer. Handles the result of the ATTENTION dialog. |
954 */ | 949 */ |
955 void | 950 void |
956 goto_buffer( | 951 goto_buffer( |
957 exarg_T *eap, | 952 exarg_T *eap, |
958 int start, | 953 int start, |
959 int dir, | 954 int dir, |
960 int count) | 955 int count) |
961 { | 956 { |
962 # if defined(HAS_SWAP_EXISTS_ACTION) | 957 #if defined(HAS_SWAP_EXISTS_ACTION) |
963 bufref_T old_curbuf; | 958 bufref_T old_curbuf; |
964 | 959 |
965 set_bufref(&old_curbuf, curbuf); | 960 set_bufref(&old_curbuf, curbuf); |
966 | 961 |
967 swap_exists_action = SEA_DIALOG; | 962 swap_exists_action = SEA_DIALOG; |
968 # endif | 963 #endif |
969 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | 964 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, |
970 start, dir, count, eap->forceit); | 965 start, dir, count, eap->forceit); |
971 # if defined(HAS_SWAP_EXISTS_ACTION) | 966 #if defined(HAS_SWAP_EXISTS_ACTION) |
972 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') | 967 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') |
973 { | 968 { |
974 # if defined(FEAT_EVAL) | 969 # if defined(FEAT_EVAL) |
975 cleanup_T cs; | 970 cleanup_T cs; |
976 | 971 |
977 /* Reset the error/interrupt/exception state here so that | 972 /* Reset the error/interrupt/exception state here so that |
978 * aborting() returns FALSE when closing a window. */ | 973 * aborting() returns FALSE when closing a window. */ |
979 enter_cleanup(&cs); | 974 enter_cleanup(&cs); |
980 # endif | 975 # endif |
981 | 976 |
982 /* Quitting means closing the split window, nothing else. */ | 977 /* Quitting means closing the split window, nothing else. */ |
983 win_close(curwin, TRUE); | 978 win_close(curwin, TRUE); |
984 swap_exists_action = SEA_NONE; | 979 swap_exists_action = SEA_NONE; |
985 swap_exists_did_quit = TRUE; | 980 swap_exists_did_quit = TRUE; |
986 | 981 |
987 # if defined(FEAT_EVAL) | 982 # if defined(FEAT_EVAL) |
988 /* Restore the error/interrupt/exception state if not discarded by a | 983 /* Restore the error/interrupt/exception state if not discarded by a |
989 * new aborting error, interrupt, or uncaught exception. */ | 984 * new aborting error, interrupt, or uncaught exception. */ |
990 leave_cleanup(&cs); | 985 leave_cleanup(&cs); |
991 # endif | 986 # endif |
992 } | 987 } |
993 else | 988 else |
994 handle_swap_exists(&old_curbuf); | 989 handle_swap_exists(&old_curbuf); |
995 # endif | 990 #endif |
996 } | 991 } |
997 #endif | |
998 | 992 |
999 #if defined(HAS_SWAP_EXISTS_ACTION) || defined(PROTO) | 993 #if defined(HAS_SWAP_EXISTS_ACTION) || defined(PROTO) |
1000 /* | 994 /* |
1001 * Handle the situation of swap_exists_action being set. | 995 * Handle the situation of swap_exists_action being set. |
1002 * It is allowed for "old_curbuf" to be NULL or invalid. | 996 * It is allowed for "old_curbuf" to be NULL or invalid. |
1070 } | 1064 } |
1071 swap_exists_action = SEA_NONE; | 1065 swap_exists_action = SEA_NONE; |
1072 } | 1066 } |
1073 #endif | 1067 #endif |
1074 | 1068 |
1075 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
1076 /* | 1069 /* |
1077 * do_bufdel() - delete or unload buffer(s) | 1070 * do_bufdel() - delete or unload buffer(s) |
1078 * | 1071 * |
1079 * addr_count == 0: ":bdel" - delete current buffer | 1072 * addr_count == 0: ":bdel" - delete current buffer |
1080 * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete | 1073 * addr_count == 1: ":N bdel" or ":bdel N [N ..]" - first delete |
1197 } | 1190 } |
1198 | 1191 |
1199 | 1192 |
1200 return errormsg; | 1193 return errormsg; |
1201 } | 1194 } |
1202 #endif /* FEAT_LISTCMDS */ | |
1203 | |
1204 #if defined(FEAT_LISTCMDS) || defined(FEAT_PYTHON) \ | |
1205 || defined(FEAT_PYTHON3) || defined(PROTO) | |
1206 | 1195 |
1207 static int empty_curbuf(int close_others, int forceit, int action); | 1196 static int empty_curbuf(int close_others, int forceit, int action); |
1208 | 1197 |
1209 /* | 1198 /* |
1210 * Make the current buffer empty. | 1199 * Make the current buffer empty. |
1357 | 1346 |
1358 #ifdef FEAT_GUI | 1347 #ifdef FEAT_GUI |
1359 need_mouse_correct = TRUE; | 1348 need_mouse_correct = TRUE; |
1360 #endif | 1349 #endif |
1361 | 1350 |
1362 #ifdef FEAT_LISTCMDS | |
1363 /* | 1351 /* |
1364 * delete buffer buf from memory and/or the list | 1352 * delete buffer buf from memory and/or the list |
1365 */ | 1353 */ |
1366 if (unload) | 1354 if (unload) |
1367 { | 1355 { |
1375 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) | 1363 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) |
1376 return FAIL; | 1364 return FAIL; |
1377 | 1365 |
1378 if (!forceit && bufIsChanged(buf)) | 1366 if (!forceit && bufIsChanged(buf)) |
1379 { | 1367 { |
1380 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 1368 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
1381 if ((p_confirm || cmdmod.confirm) && p_write) | 1369 if ((p_confirm || cmdmod.confirm) && p_write) |
1382 { | 1370 { |
1383 dialog_changed(buf, FALSE); | 1371 dialog_changed(buf, FALSE); |
1384 if (!bufref_valid(&bufref)) | 1372 if (!bufref_valid(&bufref)) |
1385 /* Autocommand deleted buffer, oops! It's not changed | 1373 /* Autocommand deleted buffer, oops! It's not changed |
1389 * mentioned why it fails. */ | 1377 * mentioned why it fails. */ |
1390 if (bufIsChanged(buf)) | 1378 if (bufIsChanged(buf)) |
1391 return FAIL; | 1379 return FAIL; |
1392 } | 1380 } |
1393 else | 1381 else |
1394 # endif | 1382 #endif |
1395 { | 1383 { |
1396 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), | 1384 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), |
1397 buf->b_fnum); | 1385 buf->b_fnum); |
1398 return FAIL; | 1386 return FAIL; |
1399 } | 1387 } |
1555 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) | 1543 if ((swb_flags & SWB_USETAB) && buf_jump_open_tab(buf)) |
1556 return OK; | 1544 return OK; |
1557 if (win_split(0, 0) == FAIL) | 1545 if (win_split(0, 0) == FAIL) |
1558 return FAIL; | 1546 return FAIL; |
1559 } | 1547 } |
1560 #endif | |
1561 | 1548 |
1562 /* go to current buffer - nothing to do */ | 1549 /* go to current buffer - nothing to do */ |
1563 if (buf == curbuf) | 1550 if (buf == curbuf) |
1564 return OK; | 1551 return OK; |
1565 | 1552 |
1588 } | 1575 } |
1589 | 1576 |
1590 /* Go to the other buffer. */ | 1577 /* Go to the other buffer. */ |
1591 set_curbuf(buf, action); | 1578 set_curbuf(buf, action); |
1592 | 1579 |
1593 #if defined(FEAT_LISTCMDS) | |
1594 if (action == DOBUF_SPLIT) | 1580 if (action == DOBUF_SPLIT) |
1595 { | 1581 { |
1596 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ | 1582 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ |
1597 } | 1583 } |
1598 #endif | |
1599 | 1584 |
1600 #if defined(FEAT_EVAL) | 1585 #if defined(FEAT_EVAL) |
1601 if (aborting()) /* autocmds may abort script processing */ | 1586 if (aborting()) /* autocmds may abort script processing */ |
1602 return FAIL; | 1587 return FAIL; |
1603 #endif | 1588 #endif |
1604 | 1589 |
1605 return OK; | 1590 return OK; |
1606 } | 1591 } |
1607 #endif | |
1608 | 1592 |
1609 /* | 1593 /* |
1610 * Set current buffer to "buf". Executes autocommands and closes current | 1594 * Set current buffer to "buf". Executes autocommands and closes current |
1611 * buffer. "action" tells how to close the current buffer: | 1595 * buffer. "action" tells how to close the current buffer: |
1612 * DOBUF_GOTO free or hide it | 1596 * DOBUF_GOTO free or hide it |
2409 )) | 2393 )) |
2410 return buf; | 2394 return buf; |
2411 return NULL; | 2395 return NULL; |
2412 } | 2396 } |
2413 | 2397 |
2414 #if defined(FEAT_LISTCMDS) || defined(FEAT_EVAL) || defined(FEAT_PERL) \ | |
2415 || defined(PROTO) | |
2416 /* | 2398 /* |
2417 * Find file in buffer list by a regexp pattern. | 2399 * Find file in buffer list by a regexp pattern. |
2418 * Return fnum of the found buffer. | 2400 * Return fnum of the found buffer. |
2419 * Return < 0 for error. | 2401 * Return < 0 for error. |
2420 */ | 2402 */ |
2532 EMSG2(_("E93: More than one match for %s"), pattern); | 2514 EMSG2(_("E93: More than one match for %s"), pattern); |
2533 else if (match < 0) | 2515 else if (match < 0) |
2534 EMSG2(_("E94: No matching buffer for %s"), pattern); | 2516 EMSG2(_("E94: No matching buffer for %s"), pattern); |
2535 return match; | 2517 return match; |
2536 } | 2518 } |
2537 #endif | |
2538 | 2519 |
2539 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | 2520 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) |
2540 | 2521 |
2541 /* | 2522 /* |
2542 * Find all buffer names that match. | 2523 * Find all buffer names that match. |
2642 return (count == 0 ? FAIL : OK); | 2623 return (count == 0 ? FAIL : OK); |
2643 } | 2624 } |
2644 | 2625 |
2645 #endif /* FEAT_CMDL_COMPL */ | 2626 #endif /* FEAT_CMDL_COMPL */ |
2646 | 2627 |
2647 #ifdef HAVE_BUFLIST_MATCH | |
2648 /* | 2628 /* |
2649 * Check for a match on the file name for buffer "buf" with regprog "prog". | 2629 * Check for a match on the file name for buffer "buf" with regprog "prog". |
2650 */ | 2630 */ |
2651 static char_u * | 2631 static char_u * |
2652 buflist_match( | 2632 buflist_match( |
2693 } | 2673 } |
2694 } | 2674 } |
2695 | 2675 |
2696 return match; | 2676 return match; |
2697 } | 2677 } |
2698 #endif | |
2699 | 2678 |
2700 /* | 2679 /* |
2701 * Find a file in the buffer list by buffer number. | 2680 * Find a file in the buffer list by buffer number. |
2702 */ | 2681 */ |
2703 buf_T * | 2682 buf_T * |
2938 buflist_findlnum(buf_T *buf) | 2917 buflist_findlnum(buf_T *buf) |
2939 { | 2918 { |
2940 return buflist_findfpos(buf)->lnum; | 2919 return buflist_findfpos(buf)->lnum; |
2941 } | 2920 } |
2942 | 2921 |
2943 #if defined(FEAT_LISTCMDS) || defined(PROTO) | |
2944 /* | 2922 /* |
2945 * List all known file names (for :files and :buffers command). | 2923 * List all known file names (for :files and :buffers command). |
2946 */ | 2924 */ |
2947 void | 2925 void |
2948 buflist_list(exarg_T *eap) | 2926 buflist_list(exarg_T *eap) |
3022 msg_outtrans(IObuff); | 3000 msg_outtrans(IObuff); |
3023 out_flush(); /* output one line at a time */ | 3001 out_flush(); /* output one line at a time */ |
3024 ui_breakcheck(); | 3002 ui_breakcheck(); |
3025 } | 3003 } |
3026 } | 3004 } |
3027 #endif | |
3028 | 3005 |
3029 /* | 3006 /* |
3030 * Get file name and line number for file 'fnum'. | 3007 * Get file name and line number for file 'fnum'. |
3031 * Used by DoOneCmd() for translating '%' and '#'. | 3008 * Used by DoOneCmd() for translating '%' and '#'. |
3032 * Used by insert_reg() and cmdline_paste() for '#' register. | 3009 * Used by insert_reg() and cmdline_paste() for '#' register. |
5093 | 5070 |
5094 --autocmd_no_leave; | 5071 --autocmd_no_leave; |
5095 vim_free(opened); | 5072 vim_free(opened); |
5096 } | 5073 } |
5097 | 5074 |
5098 # if defined(FEAT_LISTCMDS) || defined(PROTO) | |
5099 /* | 5075 /* |
5100 * Open a window for a number of buffers. | 5076 * Open a window for a number of buffers. |
5101 */ | 5077 */ |
5102 void | 5078 void |
5103 ex_buffer_all(exarg_T *eap) | 5079 ex_buffer_all(exarg_T *eap) |
5298 if (wp == NULL) | 5274 if (wp == NULL) |
5299 break; | 5275 break; |
5300 } | 5276 } |
5301 } | 5277 } |
5302 } | 5278 } |
5303 # endif /* FEAT_LISTCMDS */ | |
5304 | 5279 |
5305 | 5280 |
5306 static int chk_modeline(linenr_T, int); | 5281 static int chk_modeline(linenr_T, int); |
5307 | 5282 |
5308 /* | 5283 /* |