Mercurial > vim
comparison src/buffer.c @ 13380:69517d67421f v8.0.1564
patch 8.0.1564: too many #ifdefs
commit https://github.com/vim/vim/commit/f2bd8ef2b4507d02c6043affff8f7e85e3414d5f
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Mar 4 18:08:14 2018 +0100
patch 8.0.1564: too many #ifdefs
Problem: Too many #ifdefs.
Solution: Graduate the +autocmd feature. Takes away 450 #ifdefs and
increases code size of tiny Vim by only 40 Kbyte.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 04 Mar 2018 18:15:08 +0100 |
parents | b5806be0b36d |
children | 6740c499de13 |
comparison
equal
deleted
inserted
replaced
13379:0f9dd1b43244 | 13380:69517d67421f |
---|---|
61 | 61 |
62 #if 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 | |
67 static char *e_auabort = N_("E855: Autocommands caused command to abort"); | 66 static char *e_auabort = N_("E855: Autocommands caused command to abort"); |
68 #endif | |
69 | 67 |
70 /* Number of times free_buffer() was called. */ | 68 /* Number of times free_buffer() was called. */ |
71 static int buf_free_count = 0; | 69 static int buf_free_count = 0; |
72 | 70 |
73 /* Read data from buffer for retrying. */ | 71 /* Read data from buffer for retrying. */ |
114 if (!readonlymode && !BUFEMPTY()) | 112 if (!readonlymode && !BUFEMPTY()) |
115 changed(); | 113 changed(); |
116 else if (retval == OK) | 114 else if (retval == OK) |
117 unchanged(curbuf, FALSE); | 115 unchanged(curbuf, FALSE); |
118 | 116 |
119 #ifdef FEAT_AUTOCMD | |
120 if (retval == OK) | 117 if (retval == OK) |
121 { | 118 { |
122 # ifdef FEAT_EVAL | 119 #ifdef FEAT_EVAL |
123 apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE, | 120 apply_autocmds_retval(EVENT_STDINREADPOST, NULL, NULL, FALSE, |
124 curbuf, &retval); | 121 curbuf, &retval); |
125 # else | 122 #else |
126 apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf); | 123 apply_autocmds(EVENT_STDINREADPOST, NULL, NULL, FALSE, curbuf); |
127 # endif | 124 #endif |
128 } | 125 } |
129 #endif | |
130 } | 126 } |
131 return retval; | 127 return retval; |
132 } | 128 } |
133 | 129 |
134 /* | 130 /* |
141 int read_stdin, /* read file from stdin */ | 137 int read_stdin, /* read file from stdin */ |
142 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ | 138 exarg_T *eap, /* for forced 'ff' and 'fenc' or NULL */ |
143 int flags) /* extra flags for readfile() */ | 139 int flags) /* extra flags for readfile() */ |
144 { | 140 { |
145 int retval = OK; | 141 int retval = OK; |
146 #ifdef FEAT_AUTOCMD | |
147 bufref_T old_curbuf; | 142 bufref_T old_curbuf; |
148 #endif | |
149 #ifdef FEAT_SYN_HL | 143 #ifdef FEAT_SYN_HL |
150 long old_tw = curbuf->b_p_tw; | 144 long old_tw = curbuf->b_p_tw; |
151 #endif | 145 #endif |
152 int read_fifo = FALSE; | 146 int read_fifo = FALSE; |
153 | 147 |
186 check_colorcolumn(curwin); | 180 check_colorcolumn(curwin); |
187 #endif | 181 #endif |
188 return FAIL; | 182 return FAIL; |
189 } | 183 } |
190 | 184 |
191 #ifdef FEAT_AUTOCMD | |
192 /* The autocommands in readfile() may change the buffer, but only AFTER | 185 /* The autocommands in readfile() may change the buffer, but only AFTER |
193 * reading the file. */ | 186 * reading the file. */ |
194 set_bufref(&old_curbuf, curbuf); | 187 set_bufref(&old_curbuf, curbuf); |
195 modified_was_set = FALSE; | 188 modified_was_set = FALSE; |
196 #endif | |
197 | 189 |
198 /* mark cursor position as being invalid */ | 190 /* mark cursor position as being invalid */ |
199 curwin->w_valid = 0; | 191 curwin->w_valid = 0; |
200 | 192 |
201 if (curbuf->b_ffname != NULL | 193 if (curbuf->b_ffname != NULL |
287 */ | 279 */ |
288 /* When reading stdin, the buffer contents always needs writing, so set | 280 /* When reading stdin, the buffer contents always needs writing, so set |
289 * the changed flag. Unless in readonly mode: "ls | gview -". | 281 * the changed flag. Unless in readonly mode: "ls | gview -". |
290 * When interrupted and 'cpoptions' contains 'i' set changed flag. */ | 282 * When interrupted and 'cpoptions' contains 'i' set changed flag. */ |
291 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) | 283 if ((got_int && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
292 #ifdef FEAT_AUTOCMD | |
293 || modified_was_set /* ":set modified" used in autocmd */ | 284 || modified_was_set /* ":set modified" used in autocmd */ |
294 # ifdef FEAT_EVAL | 285 #ifdef FEAT_EVAL |
295 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) | 286 || (aborting() && vim_strchr(p_cpo, CPO_INTMOD) != NULL) |
296 # endif | |
297 #endif | 287 #endif |
298 ) | 288 ) |
299 changed(); | 289 changed(); |
300 else if (retval == OK && !read_stdin && !read_fifo) | 290 else if (retval == OK && !read_stdin && !read_fifo) |
301 unchanged(curbuf, FALSE); | 291 unchanged(curbuf, FALSE); |
313 /* Need to update automatic folding. Do this before the autocommands, | 303 /* Need to update automatic folding. Do this before the autocommands, |
314 * they may use the fold info. */ | 304 * they may use the fold info. */ |
315 foldUpdateAll(curwin); | 305 foldUpdateAll(curwin); |
316 #endif | 306 #endif |
317 | 307 |
318 #ifdef FEAT_AUTOCMD | |
319 /* need to set w_topline, unless some autocommand already did that. */ | 308 /* need to set w_topline, unless some autocommand already did that. */ |
320 if (!(curwin->w_valid & VALID_TOPLINE)) | 309 if (!(curwin->w_valid & VALID_TOPLINE)) |
321 { | 310 { |
322 curwin->w_topline = 1; | 311 curwin->w_topline = 1; |
323 # ifdef FEAT_DIFF | 312 #ifdef FEAT_DIFF |
324 curwin->w_topfill = 0; | 313 curwin->w_topfill = 0; |
325 # endif | 314 #endif |
326 } | 315 } |
327 # ifdef FEAT_EVAL | 316 #ifdef FEAT_EVAL |
328 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); | 317 apply_autocmds_retval(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf, &retval); |
329 # else | 318 #else |
330 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 319 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
331 # endif | |
332 #endif | 320 #endif |
333 | 321 |
334 if (retval == OK) | 322 if (retval == OK) |
335 { | 323 { |
336 #ifdef FEAT_AUTOCMD | |
337 /* | 324 /* |
338 * The autocommands may have changed the current buffer. Apply the | 325 * The autocommands may have changed the current buffer. Apply the |
339 * modelines to the correct buffer, if it still exists and is loaded. | 326 * modelines to the correct buffer, if it still exists and is loaded. |
340 */ | 327 */ |
341 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) | 328 if (bufref_valid(&old_curbuf) && old_curbuf.br_buf->b_ml.ml_mfp != NULL) |
342 { | 329 { |
343 aco_save_T aco; | 330 aco_save_T aco; |
344 | 331 |
345 /* Go to the buffer that was opened. */ | 332 /* Go to the buffer that was opened. */ |
346 aucmd_prepbuf(&aco, old_curbuf.br_buf); | 333 aucmd_prepbuf(&aco, old_curbuf.br_buf); |
347 #endif | |
348 do_modelines(0); | 334 do_modelines(0); |
349 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); | 335 curbuf->b_flags &= ~(BF_CHECK_RO | BF_NEVERLOADED); |
350 | 336 |
351 #ifdef FEAT_AUTOCMD | 337 #ifdef FEAT_EVAL |
352 # ifdef FEAT_EVAL | |
353 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, | 338 apply_autocmds_retval(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf, |
354 &retval); | 339 &retval); |
355 # else | 340 #else |
356 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | 341 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); |
357 # endif | 342 #endif |
358 | 343 |
359 /* restore curwin/curbuf and a few other things */ | 344 /* restore curwin/curbuf and a few other things */ |
360 aucmd_restbuf(&aco); | 345 aucmd_restbuf(&aco); |
361 } | 346 } |
362 #endif | |
363 } | 347 } |
364 | 348 |
365 return retval; | 349 return retval; |
366 } | 350 } |
367 | 351 |
452 win_T *win, /* if not NULL, set b_last_cursor */ | 436 win_T *win, /* if not NULL, set b_last_cursor */ |
453 buf_T *buf, | 437 buf_T *buf, |
454 int action, | 438 int action, |
455 int abort_if_last UNUSED) | 439 int abort_if_last UNUSED) |
456 { | 440 { |
457 #ifdef FEAT_AUTOCMD | |
458 int is_curbuf; | 441 int is_curbuf; |
459 int nwindows; | 442 int nwindows; |
460 bufref_T bufref; | 443 bufref_T bufref; |
461 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); | 444 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
462 win_T *the_curwin = curwin; | 445 win_T *the_curwin = curwin; |
463 tabpage_T *the_curtab = curtab; | 446 tabpage_T *the_curtab = curtab; |
464 #endif | |
465 int unload_buf = (action != 0); | 447 int unload_buf = (action != 0); |
466 int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); | 448 int del_buf = (action == DOBUF_DEL || action == DOBUF_WIPE); |
467 int wipe_buf = (action == DOBUF_WIPE); | 449 int wipe_buf = (action == DOBUF_WIPE); |
468 | 450 |
469 /* | 451 /* |
508 wipe_buf = TRUE; | 490 wipe_buf = TRUE; |
509 } | 491 } |
510 } | 492 } |
511 #endif | 493 #endif |
512 | 494 |
513 #ifdef FEAT_AUTOCMD | |
514 /* Disallow deleting the buffer when it is locked (already being closed or | 495 /* Disallow deleting the buffer when it is locked (already being closed or |
515 * halfway a command that relies on it). Unloading is allowed. */ | 496 * halfway a command that relies on it). Unloading is allowed. */ |
516 if (buf->b_locked > 0 && (del_buf || wipe_buf)) | 497 if (buf->b_locked > 0 && (del_buf || wipe_buf)) |
517 { | 498 { |
518 EMSG(_("E937: Attempt to delete a buffer that is in use")); | 499 EMSG(_("E937: Attempt to delete a buffer that is in use")); |
519 return; | 500 return; |
520 } | 501 } |
521 #endif | |
522 | 502 |
523 /* check no autocommands closed the window */ | 503 /* check no autocommands closed the window */ |
524 if (win != NULL && win_valid_any_tab(win)) | 504 if (win != NULL && win_valid_any_tab(win)) |
525 { | 505 { |
526 /* Set b_last_cursor when closing the last window for the buffer. | 506 /* Set b_last_cursor when closing the last window for the buffer. |
532 buflist_setfpos(buf, win, | 512 buflist_setfpos(buf, win, |
533 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, | 513 win->w_cursor.lnum == 1 ? 0 : win->w_cursor.lnum, |
534 win->w_cursor.col, TRUE); | 514 win->w_cursor.col, TRUE); |
535 } | 515 } |
536 | 516 |
537 #ifdef FEAT_AUTOCMD | |
538 set_bufref(&bufref, buf); | 517 set_bufref(&bufref, buf); |
539 | 518 |
540 /* When the buffer is no longer in a window, trigger BufWinLeave */ | 519 /* When the buffer is no longer in a window, trigger BufWinLeave */ |
541 if (buf->b_nwindows == 1) | 520 if (buf->b_nwindows == 1) |
542 { | 521 { |
568 --buf->b_locked; | 547 --buf->b_locked; |
569 if (abort_if_last && one_window()) | 548 if (abort_if_last && one_window()) |
570 /* Autocommands made this the only window. */ | 549 /* Autocommands made this the only window. */ |
571 goto aucmd_abort; | 550 goto aucmd_abort; |
572 } | 551 } |
573 # ifdef FEAT_EVAL | 552 #ifdef FEAT_EVAL |
574 if (aborting()) /* autocmds may abort script processing */ | 553 if (aborting()) /* autocmds may abort script processing */ |
575 return; | 554 return; |
576 # endif | 555 #endif |
577 } | 556 } |
578 | 557 |
579 /* If the buffer was in curwin and the window has changed, go back to that | 558 /* If the buffer was in curwin and the window has changed, go back to that |
580 * window, if it still exists. This avoids that ":edit x" triggering a | 559 * window, if it still exists. This avoids that ":edit x" triggering a |
581 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ | 560 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */ |
585 goto_tabpage_win(the_curtab, the_curwin); | 564 goto_tabpage_win(the_curtab, the_curwin); |
586 unblock_autocmds(); | 565 unblock_autocmds(); |
587 } | 566 } |
588 | 567 |
589 nwindows = buf->b_nwindows; | 568 nwindows = buf->b_nwindows; |
590 #endif | |
591 | 569 |
592 /* decrease the link count from windows (unless not in any window) */ | 570 /* decrease the link count from windows (unless not in any window) */ |
593 if (buf->b_nwindows > 0) | 571 if (buf->b_nwindows > 0) |
594 --buf->b_nwindows; | 572 --buf->b_nwindows; |
595 | 573 |
618 | 596 |
619 /* | 597 /* |
620 * Free all things allocated for this buffer. | 598 * Free all things allocated for this buffer. |
621 * Also calls the "BufDelete" autocommands when del_buf is TRUE. | 599 * Also calls the "BufDelete" autocommands when del_buf is TRUE. |
622 */ | 600 */ |
623 #ifdef FEAT_AUTOCMD | |
624 /* Remember if we are closing the current buffer. Restore the number of | 601 /* Remember if we are closing the current buffer. Restore the number of |
625 * windows, so that autocommands in buf_freeall() don't get confused. */ | 602 * windows, so that autocommands in buf_freeall() don't get confused. */ |
626 is_curbuf = (buf == curbuf); | 603 is_curbuf = (buf == curbuf); |
627 buf->b_nwindows = nwindows; | 604 buf->b_nwindows = nwindows; |
628 #endif | |
629 | 605 |
630 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); | 606 buf_freeall(buf, (del_buf ? BFA_DEL : 0) + (wipe_buf ? BFA_WIPE : 0)); |
631 | 607 |
632 #ifdef FEAT_AUTOCMD | |
633 /* Autocommands may have deleted the buffer. */ | 608 /* Autocommands may have deleted the buffer. */ |
634 if (!bufref_valid(&bufref)) | 609 if (!bufref_valid(&bufref)) |
635 return; | 610 return; |
636 # ifdef FEAT_EVAL | 611 #ifdef FEAT_EVAL |
637 if (aborting()) /* autocmds may abort script processing */ | 612 if (aborting()) /* autocmds may abort script processing */ |
638 return; | 613 return; |
639 # endif | 614 #endif |
640 | 615 |
641 /* | 616 /* |
642 * It's possible that autocommands change curbuf to the one being deleted. | 617 * It's possible that autocommands change curbuf to the one being deleted. |
643 * This might cause the previous curbuf to be deleted unexpectedly. But | 618 * This might cause the previous curbuf to be deleted unexpectedly. But |
644 * in some cases it's OK to delete the curbuf, because a new one is | 619 * in some cases it's OK to delete the curbuf, because a new one is |
653 | 628 |
654 /* Autocommands may have opened or closed windows for this buffer. | 629 /* Autocommands may have opened or closed windows for this buffer. |
655 * Decrement the count for the close we do here. */ | 630 * Decrement the count for the close we do here. */ |
656 if (buf->b_nwindows > 0) | 631 if (buf->b_nwindows > 0) |
657 --buf->b_nwindows; | 632 --buf->b_nwindows; |
658 #endif | |
659 | 633 |
660 /* | 634 /* |
661 * Remove the buffer from the list. | 635 * Remove the buffer from the list. |
662 */ | 636 */ |
663 if (wipe_buf) | 637 if (wipe_buf) |
730 * BFA_KEEP_UNDO do not free undo information | 704 * BFA_KEEP_UNDO do not free undo information |
731 */ | 705 */ |
732 void | 706 void |
733 buf_freeall(buf_T *buf, int flags) | 707 buf_freeall(buf_T *buf, int flags) |
734 { | 708 { |
735 #ifdef FEAT_AUTOCMD | |
736 int is_curbuf = (buf == curbuf); | 709 int is_curbuf = (buf == curbuf); |
737 bufref_T bufref; | 710 bufref_T bufref; |
738 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); | 711 int is_curwin = (curwin != NULL && curwin->w_buffer == buf); |
739 win_T *the_curwin = curwin; | 712 win_T *the_curwin = curwin; |
740 tabpage_T *the_curtab = curtab; | 713 tabpage_T *the_curtab = curtab; |
776 block_autocmds(); | 749 block_autocmds(); |
777 goto_tabpage_win(the_curtab, the_curwin); | 750 goto_tabpage_win(the_curtab, the_curwin); |
778 unblock_autocmds(); | 751 unblock_autocmds(); |
779 } | 752 } |
780 | 753 |
781 # ifdef FEAT_EVAL | 754 #ifdef FEAT_EVAL |
782 if (aborting()) /* autocmds may abort script processing */ | 755 if (aborting()) /* autocmds may abort script processing */ |
783 return; | 756 return; |
784 # endif | 757 #endif |
785 | 758 |
786 /* | 759 /* |
787 * It's possible that autocommands change curbuf to the one being deleted. | 760 * It's possible that autocommands change curbuf to the one being deleted. |
788 * This might cause curbuf to be deleted unexpectedly. But in some cases | 761 * This might cause curbuf to be deleted unexpectedly. But in some cases |
789 * it's OK to delete the curbuf, because a new one is obtained anyway. | 762 * it's OK to delete the curbuf, because a new one is obtained anyway. |
790 * Therefore only return if curbuf changed to the deleted buffer. | 763 * Therefore only return if curbuf changed to the deleted buffer. |
791 */ | 764 */ |
792 if (buf == curbuf && !is_curbuf) | 765 if (buf == curbuf && !is_curbuf) |
793 return; | 766 return; |
794 #endif | |
795 #ifdef FEAT_DIFF | 767 #ifdef FEAT_DIFF |
796 diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ | 768 diff_buf_delete(buf); /* Can't use 'diff' for unloaded buffer. */ |
797 #endif | 769 #endif |
798 #ifdef FEAT_SYN_HL | 770 #ifdef FEAT_SYN_HL |
799 /* Remove any ownsyntax, unless exiting. */ | 771 /* Remove any ownsyntax, unless exiting. */ |
868 free_terminal(buf); | 840 free_terminal(buf); |
869 #endif | 841 #endif |
870 | 842 |
871 buf_hashtab_remove(buf); | 843 buf_hashtab_remove(buf); |
872 | 844 |
873 #ifdef FEAT_AUTOCMD | |
874 aubuflocal_remove(buf); | 845 aubuflocal_remove(buf); |
875 | 846 |
876 if (autocmd_busy) | 847 if (autocmd_busy) |
877 { | 848 { |
878 /* Do not free the buffer structure while autocommands are executing, | 849 /* Do not free the buffer structure while autocommands are executing, |
879 * it's still needed. Free it when autocmd_busy is reset. */ | 850 * it's still needed. Free it when autocmd_busy is reset. */ |
880 buf->b_next = au_pending_free_buf; | 851 buf->b_next = au_pending_free_buf; |
881 au_pending_free_buf = buf; | 852 au_pending_free_buf = buf; |
882 } | 853 } |
883 else | 854 else |
884 #endif | |
885 vim_free(buf); | 855 vim_free(buf); |
886 } | 856 } |
887 | 857 |
888 /* | 858 /* |
889 * Initializes b:changedtick. | 859 * Initializes b:changedtick. |
992 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, | 962 (void)do_buffer(*eap->cmd == 's' ? DOBUF_SPLIT : DOBUF_GOTO, |
993 start, dir, count, eap->forceit); | 963 start, dir, count, eap->forceit); |
994 # if defined(HAS_SWAP_EXISTS_ACTION) | 964 # if defined(HAS_SWAP_EXISTS_ACTION) |
995 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') | 965 if (swap_exists_action == SEA_QUIT && *eap->cmd == 's') |
996 { | 966 { |
997 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 967 # if defined(FEAT_EVAL) |
998 cleanup_T cs; | 968 cleanup_T cs; |
999 | 969 |
1000 /* Reset the error/interrupt/exception state here so that | 970 /* Reset the error/interrupt/exception state here so that |
1001 * aborting() returns FALSE when closing a window. */ | 971 * aborting() returns FALSE when closing a window. */ |
1002 enter_cleanup(&cs); | 972 enter_cleanup(&cs); |
1005 /* Quitting means closing the split window, nothing else. */ | 975 /* Quitting means closing the split window, nothing else. */ |
1006 win_close(curwin, TRUE); | 976 win_close(curwin, TRUE); |
1007 swap_exists_action = SEA_NONE; | 977 swap_exists_action = SEA_NONE; |
1008 swap_exists_did_quit = TRUE; | 978 swap_exists_did_quit = TRUE; |
1009 | 979 |
1010 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 980 # if defined(FEAT_EVAL) |
1011 /* Restore the error/interrupt/exception state if not discarded by a | 981 /* Restore the error/interrupt/exception state if not discarded by a |
1012 * new aborting error, interrupt, or uncaught exception. */ | 982 * new aborting error, interrupt, or uncaught exception. */ |
1013 leave_cleanup(&cs); | 983 leave_cleanup(&cs); |
1014 # endif | 984 # endif |
1015 } | 985 } |
1025 * It is allowed for "old_curbuf" to be NULL or invalid. | 995 * It is allowed for "old_curbuf" to be NULL or invalid. |
1026 */ | 996 */ |
1027 void | 997 void |
1028 handle_swap_exists(bufref_T *old_curbuf) | 998 handle_swap_exists(bufref_T *old_curbuf) |
1029 { | 999 { |
1030 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1000 # if defined(FEAT_EVAL) |
1031 cleanup_T cs; | 1001 cleanup_T cs; |
1032 # endif | 1002 # endif |
1033 #ifdef FEAT_SYN_HL | 1003 # ifdef FEAT_SYN_HL |
1034 long old_tw = curbuf->b_p_tw; | 1004 long old_tw = curbuf->b_p_tw; |
1035 #endif | 1005 # endif |
1036 buf_T *buf; | 1006 buf_T *buf; |
1037 | 1007 |
1038 if (swap_exists_action == SEA_QUIT) | 1008 if (swap_exists_action == SEA_QUIT) |
1039 { | 1009 { |
1040 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1010 # if defined(FEAT_EVAL) |
1041 /* Reset the error/interrupt/exception state here so that | 1011 /* Reset the error/interrupt/exception state here so that |
1042 * aborting() returns FALSE when closing a buffer. */ | 1012 * aborting() returns FALSE when closing a buffer. */ |
1043 enter_cleanup(&cs); | 1013 enter_cleanup(&cs); |
1044 # endif | 1014 # endif |
1045 | 1015 |
1055 else | 1025 else |
1056 buf = old_curbuf->br_buf; | 1026 buf = old_curbuf->br_buf; |
1057 if (buf != NULL) | 1027 if (buf != NULL) |
1058 { | 1028 { |
1059 enter_buffer(buf); | 1029 enter_buffer(buf); |
1060 #ifdef FEAT_SYN_HL | 1030 # ifdef FEAT_SYN_HL |
1061 if (old_tw != curbuf->b_p_tw) | 1031 if (old_tw != curbuf->b_p_tw) |
1062 check_colorcolumn(curwin); | 1032 check_colorcolumn(curwin); |
1063 #endif | 1033 # endif |
1064 } | 1034 } |
1065 /* If "old_curbuf" is NULL we are in big trouble here... */ | 1035 /* If "old_curbuf" is NULL we are in big trouble here... */ |
1066 | 1036 |
1067 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1037 # if defined(FEAT_EVAL) |
1068 /* Restore the error/interrupt/exception state if not discarded by a | 1038 /* Restore the error/interrupt/exception state if not discarded by a |
1069 * new aborting error, interrupt, or uncaught exception. */ | 1039 * new aborting error, interrupt, or uncaught exception. */ |
1070 leave_cleanup(&cs); | 1040 leave_cleanup(&cs); |
1071 # endif | 1041 # endif |
1072 } | 1042 } |
1073 else if (swap_exists_action == SEA_RECOVER) | 1043 else if (swap_exists_action == SEA_RECOVER) |
1074 { | 1044 { |
1075 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1045 # if defined(FEAT_EVAL) |
1076 /* Reset the error/interrupt/exception state here so that | 1046 /* Reset the error/interrupt/exception state here so that |
1077 * aborting() returns FALSE when closing a buffer. */ | 1047 * aborting() returns FALSE when closing a buffer. */ |
1078 enter_cleanup(&cs); | 1048 enter_cleanup(&cs); |
1079 # endif | 1049 # endif |
1080 | 1050 |
1083 ml_recover(); | 1053 ml_recover(); |
1084 MSG_PUTS("\n"); /* don't overwrite the last message */ | 1054 MSG_PUTS("\n"); /* don't overwrite the last message */ |
1085 cmdline_row = msg_row; | 1055 cmdline_row = msg_row; |
1086 do_modelines(0); | 1056 do_modelines(0); |
1087 | 1057 |
1088 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1058 # if defined(FEAT_EVAL) |
1089 /* Restore the error/interrupt/exception state if not discarded by a | 1059 /* Restore the error/interrupt/exception state if not discarded by a |
1090 * new aborting error, interrupt, or uncaught exception. */ | 1060 * new aborting error, interrupt, or uncaught exception. */ |
1091 leave_cleanup(&cs); | 1061 leave_cleanup(&cs); |
1092 # endif | 1062 # endif |
1093 } | 1063 } |
1398 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) | 1368 if (action != DOBUF_WIPE && buf->b_ml.ml_mfp == NULL && !buf->b_p_bl) |
1399 return FAIL; | 1369 return FAIL; |
1400 | 1370 |
1401 if (!forceit && bufIsChanged(buf)) | 1371 if (!forceit && bufIsChanged(buf)) |
1402 { | 1372 { |
1403 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 1373 # if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
1404 if ((p_confirm || cmdmod.confirm) && p_write) | 1374 if ((p_confirm || cmdmod.confirm) && p_write) |
1405 { | 1375 { |
1406 dialog_changed(buf, FALSE); | 1376 dialog_changed(buf, FALSE); |
1407 # ifdef FEAT_AUTOCMD | |
1408 if (!bufref_valid(&bufref)) | 1377 if (!bufref_valid(&bufref)) |
1409 /* Autocommand deleted buffer, oops! It's not changed | 1378 /* Autocommand deleted buffer, oops! It's not changed |
1410 * now. */ | 1379 * now. */ |
1411 return FAIL; | 1380 return FAIL; |
1412 # endif | |
1413 /* If it's still changed fail silently, the dialog already | 1381 /* If it's still changed fail silently, the dialog already |
1414 * mentioned why it fails. */ | 1382 * mentioned why it fails. */ |
1415 if (bufIsChanged(buf)) | 1383 if (bufIsChanged(buf)) |
1416 return FAIL; | 1384 return FAIL; |
1417 } | 1385 } |
1418 else | 1386 else |
1419 #endif | 1387 # endif |
1420 { | 1388 { |
1421 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), | 1389 EMSGN(_("E89: No write since last change for buffer %ld (add ! to override)"), |
1422 buf->b_fnum); | 1390 buf->b_fnum); |
1423 return FAIL; | 1391 return FAIL; |
1424 } | 1392 } |
1442 * If the deleted buffer is the current one, close the current window | 1410 * If the deleted buffer is the current one, close the current window |
1443 * (unless it's the only window). Repeat this so long as we end up in | 1411 * (unless it's the only window). Repeat this so long as we end up in |
1444 * a window with this buffer. | 1412 * a window with this buffer. |
1445 */ | 1413 */ |
1446 while (buf == curbuf | 1414 while (buf == curbuf |
1447 #ifdef FEAT_AUTOCMD | |
1448 && !(curwin->w_closing || curwin->w_buffer->b_locked > 0) | 1415 && !(curwin->w_closing || curwin->w_buffer->b_locked > 0) |
1449 #endif | |
1450 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) | 1416 && (!ONE_WINDOW || first_tabpage->tp_next != NULL)) |
1451 { | 1417 { |
1452 if (win_close(curwin, FALSE) == FAIL) | 1418 if (win_close(curwin, FALSE) == FAIL) |
1453 break; | 1419 break; |
1454 } | 1420 } |
1474 * then before the current buffer. | 1440 * then before the current buffer. |
1475 * Finally use any buffer. | 1441 * Finally use any buffer. |
1476 */ | 1442 */ |
1477 buf = NULL; /* selected buffer */ | 1443 buf = NULL; /* selected buffer */ |
1478 bp = NULL; /* used when no loaded buffer found */ | 1444 bp = NULL; /* used when no loaded buffer found */ |
1479 #ifdef FEAT_AUTOCMD | |
1480 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) | 1445 if (au_new_curbuf.br_buf != NULL && bufref_valid(&au_new_curbuf)) |
1481 buf = au_new_curbuf.br_buf; | 1446 buf = au_new_curbuf.br_buf; |
1482 # ifdef FEAT_JUMPLIST | |
1483 else | |
1484 # endif | |
1485 #endif | |
1486 #ifdef FEAT_JUMPLIST | 1447 #ifdef FEAT_JUMPLIST |
1487 if (curwin->w_jumplistlen > 0) | 1448 else if (curwin->w_jumplistlen > 0) |
1488 { | 1449 { |
1489 int jumpidx; | 1450 int jumpidx; |
1490 | 1451 |
1491 jumpidx = curwin->w_jumplistidx - 1; | 1452 jumpidx = curwin->w_jumplistidx - 1; |
1492 if (jumpidx < 0) | 1453 if (jumpidx < 0) |
1601 if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) | 1562 if (action == DOBUF_GOTO && !can_abandon(curbuf, forceit)) |
1602 { | 1563 { |
1603 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) | 1564 #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG) |
1604 if ((p_confirm || cmdmod.confirm) && p_write) | 1565 if ((p_confirm || cmdmod.confirm) && p_write) |
1605 { | 1566 { |
1606 # ifdef FEAT_AUTOCMD | |
1607 bufref_T bufref; | 1567 bufref_T bufref; |
1608 | 1568 |
1609 set_bufref(&bufref, buf); | 1569 set_bufref(&bufref, buf); |
1610 # endif | |
1611 dialog_changed(curbuf, FALSE); | 1570 dialog_changed(curbuf, FALSE); |
1612 # ifdef FEAT_AUTOCMD | |
1613 if (!bufref_valid(&bufref)) | 1571 if (!bufref_valid(&bufref)) |
1614 /* Autocommand deleted buffer, oops! */ | 1572 /* Autocommand deleted buffer, oops! */ |
1615 return FAIL; | 1573 return FAIL; |
1616 # endif | |
1617 } | 1574 } |
1618 if (bufIsChanged(curbuf)) | 1575 if (bufIsChanged(curbuf)) |
1619 #endif | 1576 #endif |
1620 { | 1577 { |
1621 no_write_message(); | 1578 no_write_message(); |
1632 { | 1589 { |
1633 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ | 1590 RESET_BINDING(curwin); /* reset 'scrollbind' and 'cursorbind' */ |
1634 } | 1591 } |
1635 #endif | 1592 #endif |
1636 | 1593 |
1637 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1594 #if defined(FEAT_EVAL) |
1638 if (aborting()) /* autocmds may abort script processing */ | 1595 if (aborting()) /* autocmds may abort script processing */ |
1639 return FAIL; | 1596 return FAIL; |
1640 #endif | 1597 #endif |
1641 | 1598 |
1642 return OK; | 1599 return OK; |
1676 */ | 1633 */ |
1677 prevbuf = curbuf; | 1634 prevbuf = curbuf; |
1678 set_bufref(&prevbufref, prevbuf); | 1635 set_bufref(&prevbufref, prevbuf); |
1679 set_bufref(&newbufref, buf); | 1636 set_bufref(&newbufref, buf); |
1680 | 1637 |
1681 #ifdef FEAT_AUTOCMD | |
1682 /* Autocommands may delete the curren buffer and/or the buffer we wan to go | 1638 /* Autocommands may delete the curren buffer and/or the buffer we wan to go |
1683 * to. In those cases don't close the buffer. */ | 1639 * to. In those cases don't close the buffer. */ |
1684 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) | 1640 if (!apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf) |
1685 || (bufref_valid(&prevbufref) | 1641 || (bufref_valid(&prevbufref) |
1686 && bufref_valid(&newbufref) | 1642 && bufref_valid(&newbufref) |
1687 # ifdef FEAT_EVAL | 1643 #ifdef FEAT_EVAL |
1688 && !aborting() | 1644 && !aborting() |
1689 # endif | 1645 #endif |
1690 )) | 1646 )) |
1691 #endif | |
1692 { | 1647 { |
1693 #ifdef FEAT_SYN_HL | 1648 #ifdef FEAT_SYN_HL |
1694 if (prevbuf == curwin->w_buffer) | 1649 if (prevbuf == curwin->w_buffer) |
1695 reset_synblock(curwin); | 1650 reset_synblock(curwin); |
1696 #endif | 1651 #endif |
1697 if (unload) | 1652 if (unload) |
1698 close_windows(prevbuf, FALSE); | 1653 close_windows(prevbuf, FALSE); |
1699 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1654 #if defined(FEAT_EVAL) |
1700 if (bufref_valid(&prevbufref) && !aborting()) | 1655 if (bufref_valid(&prevbufref) && !aborting()) |
1701 #else | 1656 #else |
1702 if (bufref_valid(&prevbufref)) | 1657 if (bufref_valid(&prevbufref)) |
1703 #endif | 1658 #endif |
1704 { | 1659 { |
1712 if (curwin != previouswin && win_valid(previouswin)) | 1667 if (curwin != previouswin && win_valid(previouswin)) |
1713 /* autocommands changed curwin, Grr! */ | 1668 /* autocommands changed curwin, Grr! */ |
1714 curwin = previouswin; | 1669 curwin = previouswin; |
1715 } | 1670 } |
1716 } | 1671 } |
1717 #ifdef FEAT_AUTOCMD | |
1718 /* An autocommand may have deleted "buf", already entered it (e.g., when | 1672 /* An autocommand may have deleted "buf", already entered it (e.g., when |
1719 * it did ":bunload") or aborted the script processing. | 1673 * it did ":bunload") or aborted the script processing. |
1720 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ | 1674 * If curwin->w_buffer is null, enter_buffer() will make it valid again */ |
1721 if ((buf_valid(buf) && buf != curbuf | 1675 if ((buf_valid(buf) && buf != curbuf |
1722 # ifdef FEAT_EVAL | 1676 #ifdef FEAT_EVAL |
1723 && !aborting() | 1677 && !aborting() |
1724 # endif | 1678 #endif |
1725 ) || curwin->w_buffer == NULL) | 1679 ) || curwin->w_buffer == NULL) |
1726 #endif | |
1727 { | 1680 { |
1728 enter_buffer(buf); | 1681 enter_buffer(buf); |
1729 #ifdef FEAT_SYN_HL | 1682 #ifdef FEAT_SYN_HL |
1730 if (old_tw != curbuf->b_p_tw) | 1683 if (old_tw != curbuf->b_p_tw) |
1731 check_colorcolumn(curwin); | 1684 check_colorcolumn(curwin); |
1771 curwin->w_cursor.col = 0; | 1724 curwin->w_cursor.col = 0; |
1772 #ifdef FEAT_VIRTUALEDIT | 1725 #ifdef FEAT_VIRTUALEDIT |
1773 curwin->w_cursor.coladd = 0; | 1726 curwin->w_cursor.coladd = 0; |
1774 #endif | 1727 #endif |
1775 curwin->w_set_curswant = TRUE; | 1728 curwin->w_set_curswant = TRUE; |
1776 #ifdef FEAT_AUTOCMD | |
1777 curwin->w_topline_was_set = FALSE; | 1729 curwin->w_topline_was_set = FALSE; |
1778 #endif | |
1779 | 1730 |
1780 /* mark cursor position as being invalid */ | 1731 /* mark cursor position as being invalid */ |
1781 curwin->w_valid = 0; | 1732 curwin->w_valid = 0; |
1782 | 1733 |
1783 /* Make sure the buffer is loaded. */ | 1734 /* Make sure the buffer is loaded. */ |
1784 if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ | 1735 if (curbuf->b_ml.ml_mfp == NULL) /* need to load the file */ |
1785 { | 1736 { |
1786 #ifdef FEAT_AUTOCMD | |
1787 /* If there is no filetype, allow for detecting one. Esp. useful for | 1737 /* If there is no filetype, allow for detecting one. Esp. useful for |
1788 * ":ball" used in a autocommand. If there already is a filetype we | 1738 * ":ball" used in a autocommand. If there already is a filetype we |
1789 * might prefer to keep it. */ | 1739 * might prefer to keep it. */ |
1790 if (*curbuf->b_p_ft == NUL) | 1740 if (*curbuf->b_p_ft == NUL) |
1791 did_filetype = FALSE; | 1741 did_filetype = FALSE; |
1792 #endif | |
1793 | 1742 |
1794 open_buffer(FALSE, NULL, 0); | 1743 open_buffer(FALSE, NULL, 0); |
1795 } | 1744 } |
1796 else | 1745 else |
1797 { | 1746 { |
1798 if (!msg_silent) | 1747 if (!msg_silent) |
1799 need_fileinfo = TRUE; /* display file info after redraw */ | 1748 need_fileinfo = TRUE; /* display file info after redraw */ |
1800 (void)buf_check_timestamp(curbuf, FALSE); /* check if file changed */ | 1749 (void)buf_check_timestamp(curbuf, FALSE); /* check if file changed */ |
1801 #ifdef FEAT_AUTOCMD | |
1802 curwin->w_topline = 1; | 1750 curwin->w_topline = 1; |
1803 # ifdef FEAT_DIFF | 1751 #ifdef FEAT_DIFF |
1804 curwin->w_topfill = 0; | 1752 curwin->w_topfill = 0; |
1805 # endif | 1753 #endif |
1806 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); | 1754 apply_autocmds(EVENT_BUFENTER, NULL, NULL, FALSE, curbuf); |
1807 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); | 1755 apply_autocmds(EVENT_BUFWINENTER, NULL, NULL, FALSE, curbuf); |
1808 #endif | |
1809 } | 1756 } |
1810 | 1757 |
1811 /* If autocommands did not change the cursor position, restore cursor lnum | 1758 /* If autocommands did not change the cursor position, restore cursor lnum |
1812 * and possibly cursor col. */ | 1759 * and possibly cursor col. */ |
1813 if (curwin->w_cursor.lnum == 1 && inindent(0)) | 1760 if (curwin->w_cursor.lnum == 1 && inindent(0)) |
1815 | 1762 |
1816 check_arg_idx(curwin); /* check for valid arg_idx */ | 1763 check_arg_idx(curwin); /* check for valid arg_idx */ |
1817 #ifdef FEAT_TITLE | 1764 #ifdef FEAT_TITLE |
1818 maketitle(); | 1765 maketitle(); |
1819 #endif | 1766 #endif |
1820 #ifdef FEAT_AUTOCMD | |
1821 /* when autocmds didn't change it */ | 1767 /* when autocmds didn't change it */ |
1822 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) | 1768 if (curwin->w_topline == 1 && !curwin->w_topline_was_set) |
1823 #endif | |
1824 scroll_cursor_halfway(FALSE); /* redisplay at correct position */ | 1769 scroll_cursor_halfway(FALSE); /* redisplay at correct position */ |
1825 | 1770 |
1826 #ifdef FEAT_NETBEANS_INTG | 1771 #ifdef FEAT_NETBEANS_INTG |
1827 /* Send fileOpened event because we've changed buffers. */ | 1772 /* Send fileOpened event because we've changed buffers. */ |
1828 netbeans_file_activated(curbuf); | 1773 netbeans_file_activated(curbuf); |
1946 * already */ | 1891 * already */ |
1947 buf_copy_options(buf, 0); | 1892 buf_copy_options(buf, 0); |
1948 | 1893 |
1949 if ((flags & BLN_LISTED) && !buf->b_p_bl) | 1894 if ((flags & BLN_LISTED) && !buf->b_p_bl) |
1950 { | 1895 { |
1951 #ifdef FEAT_AUTOCMD | |
1952 bufref_T bufref; | 1896 bufref_T bufref; |
1953 #endif | 1897 |
1954 buf->b_p_bl = TRUE; | 1898 buf->b_p_bl = TRUE; |
1955 #ifdef FEAT_AUTOCMD | |
1956 set_bufref(&bufref, buf); | 1899 set_bufref(&bufref, buf); |
1957 if (!(flags & BLN_DUMMY)) | 1900 if (!(flags & BLN_DUMMY)) |
1958 { | 1901 { |
1959 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) | 1902 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
1960 && !bufref_valid(&bufref)) | 1903 && !bufref_valid(&bufref)) |
1961 return NULL; | 1904 return NULL; |
1962 } | 1905 } |
1963 #endif | |
1964 } | 1906 } |
1965 return buf; | 1907 return buf; |
1966 } | 1908 } |
1967 | 1909 |
1968 /* | 1910 /* |
1979 && curbuf->b_ffname == NULL | 1921 && curbuf->b_ffname == NULL |
1980 && curbuf->b_nwindows <= 1 | 1922 && curbuf->b_nwindows <= 1 |
1981 && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())) | 1923 && (curbuf->b_ml.ml_mfp == NULL || BUFEMPTY())) |
1982 { | 1924 { |
1983 buf = curbuf; | 1925 buf = curbuf; |
1984 #ifdef FEAT_AUTOCMD | |
1985 /* It's like this buffer is deleted. Watch out for autocommands that | 1926 /* It's like this buffer is deleted. Watch out for autocommands that |
1986 * change curbuf! If that happens, allocate a new buffer anyway. */ | 1927 * change curbuf! If that happens, allocate a new buffer anyway. */ |
1987 if (curbuf->b_p_bl) | 1928 if (curbuf->b_p_bl) |
1988 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | 1929 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); |
1989 if (buf == curbuf) | 1930 if (buf == curbuf) |
1990 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); | 1931 apply_autocmds(EVENT_BUFWIPEOUT, NULL, NULL, FALSE, curbuf); |
1991 # ifdef FEAT_EVAL | 1932 #ifdef FEAT_EVAL |
1992 if (aborting()) /* autocmds may abort script processing */ | 1933 if (aborting()) /* autocmds may abort script processing */ |
1993 return NULL; | 1934 return NULL; |
1994 # endif | 1935 #endif |
1995 #endif | |
1996 #ifdef FEAT_AUTOCMD | |
1997 if (buf == curbuf) | 1936 if (buf == curbuf) |
1998 #endif | |
1999 { | 1937 { |
2000 /* Make sure 'bufhidden' and 'buftype' are empty */ | 1938 /* Make sure 'bufhidden' and 'buftype' are empty */ |
2001 clear_string_option(&buf->b_p_bh); | 1939 clear_string_option(&buf->b_p_bh); |
2002 clear_string_option(&buf->b_p_bt); | 1940 clear_string_option(&buf->b_p_bt); |
2003 } | 1941 } |
2047 { | 1985 { |
2048 /* free all things allocated for this buffer */ | 1986 /* free all things allocated for this buffer */ |
2049 buf_freeall(buf, 0); | 1987 buf_freeall(buf, 0); |
2050 if (buf != curbuf) /* autocommands deleted the buffer! */ | 1988 if (buf != curbuf) /* autocommands deleted the buffer! */ |
2051 return NULL; | 1989 return NULL; |
2052 #if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 1990 #if defined(FEAT_EVAL) |
2053 if (aborting()) /* autocmds may abort script processing */ | 1991 if (aborting()) /* autocmds may abort script processing */ |
2054 return NULL; | 1992 return NULL; |
2055 #endif | 1993 #endif |
2056 free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ | 1994 free_buffer_stuff(buf, FALSE); /* delete local variables et al. */ |
2057 | 1995 |
2126 buf->b_flags |= BF_DUMMY; | 2064 buf->b_flags |= BF_DUMMY; |
2127 buf_clear_file(buf); | 2065 buf_clear_file(buf); |
2128 clrallmarks(buf); /* clear marks */ | 2066 clrallmarks(buf); /* clear marks */ |
2129 fmarks_check_names(buf); /* check file marks for this file */ | 2067 fmarks_check_names(buf); /* check file marks for this file */ |
2130 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ | 2068 buf->b_p_bl = (flags & BLN_LISTED) ? TRUE : FALSE; /* init 'buflisted' */ |
2131 #ifdef FEAT_AUTOCMD | |
2132 if (!(flags & BLN_DUMMY)) | 2069 if (!(flags & BLN_DUMMY)) |
2133 { | 2070 { |
2134 bufref_T bufref; | 2071 bufref_T bufref; |
2135 | 2072 |
2136 /* Tricky: these autocommands may change the buffer list. They could | 2073 /* Tricky: these autocommands may change the buffer list. They could |
2144 { | 2081 { |
2145 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) | 2082 if (apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, buf) |
2146 && !bufref_valid(&bufref)) | 2083 && !bufref_valid(&bufref)) |
2147 return NULL; | 2084 return NULL; |
2148 } | 2085 } |
2149 # ifdef FEAT_EVAL | 2086 #ifdef FEAT_EVAL |
2150 if (aborting()) /* autocmds may abort script processing */ | 2087 if (aborting()) /* autocmds may abort script processing */ |
2151 return NULL; | 2088 return NULL; |
2152 # endif | 2089 #endif |
2153 } | 2090 } |
2154 #endif | |
2155 | 2091 |
2156 return buf; | 2092 return buf; |
2157 } | 2093 } |
2158 | 2094 |
2159 /* | 2095 /* |
2228 clear_string_option(&buf->b_s.b_p_spl); | 2164 clear_string_option(&buf->b_s.b_p_spl); |
2229 #endif | 2165 #endif |
2230 #ifdef FEAT_SEARCHPATH | 2166 #ifdef FEAT_SEARCHPATH |
2231 clear_string_option(&buf->b_p_sua); | 2167 clear_string_option(&buf->b_p_sua); |
2232 #endif | 2168 #endif |
2233 #ifdef FEAT_AUTOCMD | |
2234 clear_string_option(&buf->b_p_ft); | 2169 clear_string_option(&buf->b_p_ft); |
2235 #endif | |
2236 #ifdef FEAT_CINDENT | 2170 #ifdef FEAT_CINDENT |
2237 clear_string_option(&buf->b_p_cink); | 2171 clear_string_option(&buf->b_p_cink); |
2238 clear_string_option(&buf->b_p_cino); | 2172 clear_string_option(&buf->b_p_cino); |
2239 #endif | 2173 #endif |
2240 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) | 2174 #if defined(FEAT_CINDENT) || defined(FEAT_SMARTINDENT) |
2313 if (text_locked()) | 2247 if (text_locked()) |
2314 { | 2248 { |
2315 text_locked_msg(); | 2249 text_locked_msg(); |
2316 return FAIL; | 2250 return FAIL; |
2317 } | 2251 } |
2318 #ifdef FEAT_AUTOCMD | |
2319 if (curbuf_locked()) | 2252 if (curbuf_locked()) |
2320 return FAIL; | 2253 return FAIL; |
2321 #endif | |
2322 | 2254 |
2323 /* altfpos may be changed by getfile(), get it now */ | 2255 /* altfpos may be changed by getfile(), get it now */ |
2324 if (lnum == 0) | 2256 if (lnum == 0) |
2325 { | 2257 { |
2326 fpos = buflist_findfpos(buf); | 2258 fpos = buflist_findfpos(buf); |
4366 if (wp->w_buffer->b_help) | 4298 if (wp->w_buffer->b_help) |
4367 str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" | 4299 str = (char_u *)((opt == STL_HELPFLAG_ALT) ? ",HLP" |
4368 : _("[Help]")); | 4300 : _("[Help]")); |
4369 break; | 4301 break; |
4370 | 4302 |
4371 #ifdef FEAT_AUTOCMD | |
4372 case STL_FILETYPE: | 4303 case STL_FILETYPE: |
4373 if (*wp->w_buffer->b_p_ft != NUL | 4304 if (*wp->w_buffer->b_p_ft != NUL |
4374 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) | 4305 && STRLEN(wp->w_buffer->b_p_ft) < TMPLEN - 3) |
4375 { | 4306 { |
4376 vim_snprintf((char *)tmp, sizeof(tmp), "[%s]", | 4307 vim_snprintf((char *)tmp, sizeof(tmp), "[%s]", |
4389 for (t = tmp; *t != 0; t++) | 4320 for (t = tmp; *t != 0; t++) |
4390 *t = TOUPPER_LOC(*t); | 4321 *t = TOUPPER_LOC(*t); |
4391 str = tmp; | 4322 str = tmp; |
4392 } | 4323 } |
4393 break; | 4324 break; |
4394 #endif | |
4395 | 4325 |
4396 #if defined(FEAT_QUICKFIX) | 4326 #if defined(FEAT_QUICKFIX) |
4397 case STL_PREVIEWFLAG: | 4327 case STL_PREVIEWFLAG: |
4398 case STL_PREVIEWFLAG_ALT: | 4328 case STL_PREVIEWFLAG_ALT: |
4399 itemisflag = TRUE; | 4329 itemisflag = TRUE; |
5011 /* If the buffer was changed, and we would like to hide it, | 4941 /* If the buffer was changed, and we would like to hide it, |
5012 * try autowriting. */ | 4942 * try autowriting. */ |
5013 if (!buf_hide(buf) && buf->b_nwindows <= 1 | 4943 if (!buf_hide(buf) && buf->b_nwindows <= 1 |
5014 && bufIsChanged(buf)) | 4944 && bufIsChanged(buf)) |
5015 { | 4945 { |
5016 #ifdef FEAT_AUTOCMD | |
5017 bufref_T bufref; | 4946 bufref_T bufref; |
5018 | 4947 |
5019 set_bufref(&bufref, buf); | 4948 set_bufref(&bufref, buf); |
5020 #endif | 4949 |
5021 (void)autowrite(buf, FALSE); | 4950 (void)autowrite(buf, FALSE); |
5022 #ifdef FEAT_AUTOCMD | 4951 |
5023 /* check if autocommands removed the window */ | 4952 /* check if autocommands removed the window */ |
5024 if (!win_valid(wp) || !bufref_valid(&bufref)) | 4953 if (!win_valid(wp) || !bufref_valid(&bufref)) |
5025 { | 4954 { |
5026 wpnext = firstwin; /* start all over... */ | 4955 wpnext = firstwin; /* start all over... */ |
5027 continue; | 4956 continue; |
5028 } | 4957 } |
5029 #endif | |
5030 } | 4958 } |
5031 /* don't close last window */ | 4959 /* don't close last window */ |
5032 if (ONE_WINDOW | 4960 if (ONE_WINDOW |
5033 && (first_tabpage->tp_next == NULL || !had_tab)) | 4961 && (first_tabpage->tp_next == NULL || !had_tab)) |
5034 use_firstwin = TRUE; | 4962 use_firstwin = TRUE; |
5035 else | 4963 else |
5036 { | 4964 { |
5037 win_close(wp, !buf_hide(buf) && !bufIsChanged(buf)); | 4965 win_close(wp, !buf_hide(buf) && !bufIsChanged(buf)); |
5038 #ifdef FEAT_AUTOCMD | 4966 |
5039 /* check if autocommands removed the next window */ | 4967 /* check if autocommands removed the next window */ |
5040 if (!win_valid(wpnext)) | 4968 if (!win_valid(wpnext)) |
5041 wpnext = firstwin; /* start all over... */ | 4969 wpnext = firstwin; /* start all over... */ |
5042 #endif | |
5043 } | 4970 } |
5044 } | 4971 } |
5045 } | 4972 } |
5046 } | 4973 } |
5047 | 4974 |
5048 /* Without the ":tab" modifier only do the current tab page. */ | 4975 /* Without the ":tab" modifier only do the current tab page. */ |
5049 if (had_tab == 0 || tpnext == NULL) | 4976 if (had_tab == 0 || tpnext == NULL) |
5050 break; | 4977 break; |
5051 | 4978 |
5052 # ifdef FEAT_AUTOCMD | |
5053 /* check if autocommands removed the next tab page */ | 4979 /* check if autocommands removed the next tab page */ |
5054 if (!valid_tabpage(tpnext)) | 4980 if (!valid_tabpage(tpnext)) |
5055 tpnext = first_tabpage; /* start all over...*/ | 4981 tpnext = first_tabpage; /* start all over...*/ |
5056 # endif | 4982 |
5057 goto_tabpage_tp(tpnext, TRUE, TRUE); | 4983 goto_tabpage_tp(tpnext, TRUE, TRUE); |
5058 } | 4984 } |
5059 | 4985 |
5060 /* | 4986 /* |
5061 * Open a window for files in the argument list that don't have one. | 4987 * Open a window for files in the argument list that don't have one. |
5062 * ARGCOUNT may change while doing this, because of autocommands. | 4988 * ARGCOUNT may change while doing this, because of autocommands. |
5063 */ | 4989 */ |
5064 if (count > opened_len || count <= 0) | 4990 if (count > opened_len || count <= 0) |
5065 count = opened_len; | 4991 count = opened_len; |
5066 | 4992 |
5067 #ifdef FEAT_AUTOCMD | |
5068 /* Don't execute Win/Buf Enter/Leave autocommands here. */ | 4993 /* Don't execute Win/Buf Enter/Leave autocommands here. */ |
5069 ++autocmd_no_enter; | 4994 ++autocmd_no_enter; |
5070 ++autocmd_no_leave; | 4995 ++autocmd_no_leave; |
5071 #endif | |
5072 last_curwin = curwin; | 4996 last_curwin = curwin; |
5073 last_curtab = curtab; | 4997 last_curtab = curtab; |
5074 win_enter(lastwin, FALSE); | 4998 win_enter(lastwin, FALSE); |
5075 /* ":drop all" should re-use an empty window to avoid "--remote-tab" | 4999 /* ":drop all" should re-use an empty window to avoid "--remote-tab" |
5076 * leaving an empty tab page when executed locally. */ | 5000 * leaving an empty tab page when executed locally. */ |
5112 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); | 5036 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); |
5113 p_ea = p_ea_save; | 5037 p_ea = p_ea_save; |
5114 if (split_ret == FAIL) | 5038 if (split_ret == FAIL) |
5115 continue; | 5039 continue; |
5116 } | 5040 } |
5117 #ifdef FEAT_AUTOCMD | |
5118 else /* first window: do autocmd for leaving this buffer */ | 5041 else /* first window: do autocmd for leaving this buffer */ |
5119 --autocmd_no_leave; | 5042 --autocmd_no_leave; |
5120 #endif | |
5121 | 5043 |
5122 /* | 5044 /* |
5123 * edit file "i" | 5045 * edit file "i" |
5124 */ | 5046 */ |
5125 curwin->w_arg_idx = i; | 5047 curwin->w_arg_idx = i; |
5131 (void)do_ecmd(0, alist_name(&AARGLIST(alist)[i]), NULL, NULL, | 5053 (void)do_ecmd(0, alist_name(&AARGLIST(alist)[i]), NULL, NULL, |
5132 ECMD_ONE, | 5054 ECMD_ONE, |
5133 ((buf_hide(curwin->w_buffer) | 5055 ((buf_hide(curwin->w_buffer) |
5134 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0) | 5056 || bufIsChanged(curwin->w_buffer)) ? ECMD_HIDE : 0) |
5135 + ECMD_OLDBUF, curwin); | 5057 + ECMD_OLDBUF, curwin); |
5136 #ifdef FEAT_AUTOCMD | |
5137 if (use_firstwin) | 5058 if (use_firstwin) |
5138 ++autocmd_no_leave; | 5059 ++autocmd_no_leave; |
5139 #endif | |
5140 use_firstwin = FALSE; | 5060 use_firstwin = FALSE; |
5141 } | 5061 } |
5142 ui_breakcheck(); | 5062 ui_breakcheck(); |
5143 | 5063 |
5144 /* When ":tab" was used open a new tab for a new window repeatedly. */ | 5064 /* When ":tab" was used open a new tab for a new window repeatedly. */ |
5147 } | 5067 } |
5148 | 5068 |
5149 /* Remove the "lock" on the argument list. */ | 5069 /* Remove the "lock" on the argument list. */ |
5150 alist_unlink(alist); | 5070 alist_unlink(alist); |
5151 | 5071 |
5152 #ifdef FEAT_AUTOCMD | |
5153 --autocmd_no_enter; | 5072 --autocmd_no_enter; |
5154 #endif | 5073 |
5155 /* restore last referenced tabpage's curwin */ | 5074 /* restore last referenced tabpage's curwin */ |
5156 if (last_curtab != new_curtab) | 5075 if (last_curtab != new_curtab) |
5157 { | 5076 { |
5158 if (valid_tabpage(last_curtab)) | 5077 if (valid_tabpage(last_curtab)) |
5159 goto_tabpage_tp(last_curtab, TRUE, TRUE); | 5078 goto_tabpage_tp(last_curtab, TRUE, TRUE); |
5164 if (valid_tabpage(new_curtab)) | 5083 if (valid_tabpage(new_curtab)) |
5165 goto_tabpage_tp(new_curtab, TRUE, TRUE); | 5084 goto_tabpage_tp(new_curtab, TRUE, TRUE); |
5166 if (win_valid(new_curwin)) | 5085 if (win_valid(new_curwin)) |
5167 win_enter(new_curwin, FALSE); | 5086 win_enter(new_curwin, FALSE); |
5168 | 5087 |
5169 #ifdef FEAT_AUTOCMD | |
5170 --autocmd_no_leave; | 5088 --autocmd_no_leave; |
5171 #endif | |
5172 vim_free(opened); | 5089 vim_free(opened); |
5173 } | 5090 } |
5174 | 5091 |
5175 # if defined(FEAT_LISTCMDS) || defined(PROTO) | 5092 # if defined(FEAT_LISTCMDS) || defined(PROTO) |
5176 /* | 5093 /* |
5221 || ((cmdmod.split & WSP_VERT) | 5138 || ((cmdmod.split & WSP_VERT) |
5222 ? wp->w_height + wp->w_status_height < Rows - p_ch | 5139 ? wp->w_height + wp->w_status_height < Rows - p_ch |
5223 - tabline_height() | 5140 - tabline_height() |
5224 : wp->w_width != Columns) | 5141 : wp->w_width != Columns) |
5225 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW | 5142 || (had_tab > 0 && wp != firstwin)) && !ONE_WINDOW |
5226 #ifdef FEAT_AUTOCMD | 5143 && !(wp->w_closing || wp->w_buffer->b_locked > 0)) |
5227 && !(wp->w_closing || wp->w_buffer->b_locked > 0) | |
5228 #endif | |
5229 ) | |
5230 { | 5144 { |
5231 win_close(wp, FALSE); | 5145 win_close(wp, FALSE); |
5232 #ifdef FEAT_AUTOCMD | |
5233 wpnext = firstwin; /* just in case an autocommand does | 5146 wpnext = firstwin; /* just in case an autocommand does |
5234 something strange with windows */ | 5147 something strange with windows */ |
5235 tpnext = first_tabpage; /* start all over...*/ | 5148 tpnext = first_tabpage; /* start all over...*/ |
5236 open_wins = 0; | 5149 open_wins = 0; |
5237 #endif | |
5238 } | 5150 } |
5239 else | 5151 else |
5240 ++open_wins; | 5152 ++open_wins; |
5241 } | 5153 } |
5242 | 5154 |
5249 /* | 5161 /* |
5250 * Go through the buffer list. When a buffer doesn't have a window yet, | 5162 * Go through the buffer list. When a buffer doesn't have a window yet, |
5251 * open one. Otherwise move the window to the right position. | 5163 * open one. Otherwise move the window to the right position. |
5252 * Watch out for autocommands that delete buffers or windows! | 5164 * Watch out for autocommands that delete buffers or windows! |
5253 */ | 5165 */ |
5254 #ifdef FEAT_AUTOCMD | |
5255 /* Don't execute Win/Buf Enter/Leave autocommands here. */ | 5166 /* Don't execute Win/Buf Enter/Leave autocommands here. */ |
5256 ++autocmd_no_enter; | 5167 ++autocmd_no_enter; |
5257 #endif | |
5258 win_enter(lastwin, FALSE); | 5168 win_enter(lastwin, FALSE); |
5259 #ifdef FEAT_AUTOCMD | |
5260 ++autocmd_no_leave; | 5169 ++autocmd_no_leave; |
5261 #endif | |
5262 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) | 5170 for (buf = firstbuf; buf != NULL && open_wins < count; buf = buf->b_next) |
5263 { | 5171 { |
5264 /* Check if this buffer needs a window */ | 5172 /* Check if this buffer needs a window */ |
5265 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) | 5173 if ((!all && buf->b_ml.ml_mfp == NULL) || !buf->b_p_bl) |
5266 continue; | 5174 continue; |
5284 win_move_after(wp, curwin); | 5192 win_move_after(wp, curwin); |
5285 } | 5193 } |
5286 | 5194 |
5287 if (wp == NULL && split_ret == OK) | 5195 if (wp == NULL && split_ret == OK) |
5288 { | 5196 { |
5289 #ifdef FEAT_AUTOCMD | |
5290 bufref_T bufref; | 5197 bufref_T bufref; |
5291 | 5198 |
5292 set_bufref(&bufref, buf); | 5199 set_bufref(&bufref, buf); |
5293 #endif | 5200 |
5294 /* Split the window and put the buffer in it */ | 5201 /* Split the window and put the buffer in it */ |
5295 p_ea_save = p_ea; | 5202 p_ea_save = p_ea; |
5296 p_ea = TRUE; /* use space from all windows */ | 5203 p_ea = TRUE; /* use space from all windows */ |
5297 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); | 5204 split_ret = win_split(0, WSP_ROOM | WSP_BELOW); |
5298 ++open_wins; | 5205 ++open_wins; |
5303 /* Open the buffer in this window. */ | 5210 /* Open the buffer in this window. */ |
5304 #if defined(HAS_SWAP_EXISTS_ACTION) | 5211 #if defined(HAS_SWAP_EXISTS_ACTION) |
5305 swap_exists_action = SEA_DIALOG; | 5212 swap_exists_action = SEA_DIALOG; |
5306 #endif | 5213 #endif |
5307 set_curbuf(buf, DOBUF_GOTO); | 5214 set_curbuf(buf, DOBUF_GOTO); |
5308 #ifdef FEAT_AUTOCMD | |
5309 if (!bufref_valid(&bufref)) | 5215 if (!bufref_valid(&bufref)) |
5310 { | 5216 { |
5311 /* autocommands deleted the buffer!!! */ | 5217 /* autocommands deleted the buffer!!! */ |
5312 #if defined(HAS_SWAP_EXISTS_ACTION) | 5218 #if defined(HAS_SWAP_EXISTS_ACTION) |
5313 swap_exists_action = SEA_NONE; | 5219 swap_exists_action = SEA_NONE; |
5314 # endif | 5220 #endif |
5315 break; | 5221 break; |
5316 } | 5222 } |
5317 #endif | |
5318 #if defined(HAS_SWAP_EXISTS_ACTION) | 5223 #if defined(HAS_SWAP_EXISTS_ACTION) |
5319 if (swap_exists_action == SEA_QUIT) | 5224 if (swap_exists_action == SEA_QUIT) |
5320 { | 5225 { |
5321 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 5226 # if defined(FEAT_EVAL) |
5322 cleanup_T cs; | 5227 cleanup_T cs; |
5323 | 5228 |
5324 /* Reset the error/interrupt/exception state here so that | 5229 /* Reset the error/interrupt/exception state here so that |
5325 * aborting() returns FALSE when closing a window. */ | 5230 * aborting() returns FALSE when closing a window. */ |
5326 enter_cleanup(&cs); | 5231 enter_cleanup(&cs); |
5330 win_close(curwin, TRUE); | 5235 win_close(curwin, TRUE); |
5331 --open_wins; | 5236 --open_wins; |
5332 swap_exists_action = SEA_NONE; | 5237 swap_exists_action = SEA_NONE; |
5333 swap_exists_did_quit = TRUE; | 5238 swap_exists_did_quit = TRUE; |
5334 | 5239 |
5335 # if defined(FEAT_AUTOCMD) && defined(FEAT_EVAL) | 5240 # if defined(FEAT_EVAL) |
5336 /* Restore the error/interrupt/exception state if not | 5241 /* Restore the error/interrupt/exception state if not |
5337 * discarded by a new aborting error, interrupt, or uncaught | 5242 * discarded by a new aborting error, interrupt, or uncaught |
5338 * exception. */ | 5243 * exception. */ |
5339 leave_cleanup(&cs); | 5244 leave_cleanup(&cs); |
5340 # endif | 5245 # endif |
5357 #endif | 5262 #endif |
5358 /* When ":tab" was used open a new tab for a new window repeatedly. */ | 5263 /* When ":tab" was used open a new tab for a new window repeatedly. */ |
5359 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) | 5264 if (had_tab > 0 && tabpage_index(NULL) <= p_tpm) |
5360 cmdmod.tab = 9999; | 5265 cmdmod.tab = 9999; |
5361 } | 5266 } |
5362 #ifdef FEAT_AUTOCMD | |
5363 --autocmd_no_enter; | 5267 --autocmd_no_enter; |
5364 #endif | |
5365 win_enter(firstwin, FALSE); /* back to first window */ | 5268 win_enter(firstwin, FALSE); /* back to first window */ |
5366 #ifdef FEAT_AUTOCMD | |
5367 --autocmd_no_leave; | 5269 --autocmd_no_leave; |
5368 #endif | |
5369 | 5270 |
5370 /* | 5271 /* |
5371 * Close superfluous windows. | 5272 * Close superfluous windows. |
5372 */ | 5273 */ |
5373 for (wp = lastwin; open_wins > count; ) | 5274 for (wp = lastwin; open_wins > count; ) |
5374 { | 5275 { |
5375 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) | 5276 r = (buf_hide(wp->w_buffer) || !bufIsChanged(wp->w_buffer) |
5376 || autowrite(wp->w_buffer, FALSE) == OK); | 5277 || autowrite(wp->w_buffer, FALSE) == OK); |
5377 #ifdef FEAT_AUTOCMD | |
5378 if (!win_valid(wp)) | 5278 if (!win_valid(wp)) |
5379 { | 5279 { |
5380 /* BufWrite Autocommands made the window invalid, start over */ | 5280 /* BufWrite Autocommands made the window invalid, start over */ |
5381 wp = lastwin; | 5281 wp = lastwin; |
5382 } | 5282 } |
5383 else | 5283 else if (r) |
5384 #endif | |
5385 if (r) | |
5386 { | 5284 { |
5387 win_close(wp, !buf_hide(wp->w_buffer)); | 5285 win_close(wp, !buf_hide(wp->w_buffer)); |
5388 --open_wins; | 5286 --open_wins; |
5389 wp = lastwin; | 5287 wp = lastwin; |
5390 } | 5288 } |
6231 set_buflisted(int on) | 6129 set_buflisted(int on) |
6232 { | 6130 { |
6233 if (on != curbuf->b_p_bl) | 6131 if (on != curbuf->b_p_bl) |
6234 { | 6132 { |
6235 curbuf->b_p_bl = on; | 6133 curbuf->b_p_bl = on; |
6236 #ifdef FEAT_AUTOCMD | |
6237 if (on) | 6134 if (on) |
6238 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); | 6135 apply_autocmds(EVENT_BUFADD, NULL, NULL, FALSE, curbuf); |
6239 else | 6136 else |
6240 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); | 6137 apply_autocmds(EVENT_BUFDELETE, NULL, NULL, FALSE, curbuf); |
6241 #endif | |
6242 } | 6138 } |
6243 } | 6139 } |
6244 | 6140 |
6245 /* | 6141 /* |
6246 * Read the file for "buf" again and check if the contents changed. | 6142 * Read the file for "buf" again and check if the contents changed. |
6309 int aucmd UNUSED) /* When TRUE trigger autocommands. */ | 6205 int aucmd UNUSED) /* When TRUE trigger autocommands. */ |
6310 { | 6206 { |
6311 if (buf->b_fnum == top_file_num - 1) | 6207 if (buf->b_fnum == top_file_num - 1) |
6312 --top_file_num; | 6208 --top_file_num; |
6313 | 6209 |
6314 #ifdef FEAT_AUTOCMD | |
6315 if (!aucmd) /* Don't trigger BufDelete autocommands here. */ | 6210 if (!aucmd) /* Don't trigger BufDelete autocommands here. */ |
6316 block_autocmds(); | 6211 block_autocmds(); |
6317 #endif | 6212 |
6318 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); | 6213 close_buffer(NULL, buf, DOBUF_WIPE, FALSE); |
6319 #ifdef FEAT_AUTOCMD | 6214 |
6320 if (!aucmd) | 6215 if (!aucmd) |
6321 unblock_autocmds(); | 6216 unblock_autocmds(); |
6322 #endif | 6217 } |
6323 } |