comparison src/buffer.c @ 10082:7fc6103c6651 v7.4.2312

commit https://github.com/vim/vim/commit/5a49789a9b1f6447aeafbbbdd5b235dd10c471d5 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 3 16:29:04 2016 +0200 patch 7.4.2312 Problem: Crash when autocommand moves to another tab. (Dominique Pelle) Solution: When navigating to another window halfway the :edit command go back to the right window.
author Christian Brabandt <cb@256bit.org>
date Sat, 03 Sep 2016 16:30:06 +0200
parents 4aead6a9b7a9
children 58e6dd1d8be3
comparison
equal deleted inserted replaced
10081:a7e347d09237 10082:7fc6103c6651
664 #endif 664 #endif
665 } 665 }
666 666
667 /* 667 /*
668 * buf_freeall() - free all things allocated for a buffer that are related to 668 * buf_freeall() - free all things allocated for a buffer that are related to
669 * the file. flags: 669 * the file. Careful: get here with "curwin" NULL when exiting.
670 * flags:
670 * BFA_DEL buffer is going to be deleted 671 * BFA_DEL buffer is going to be deleted
671 * BFA_WIPE buffer is going to be wiped out 672 * BFA_WIPE buffer is going to be wiped out
672 * BFA_KEEP_UNDO do not free undo information 673 * BFA_KEEP_UNDO do not free undo information
673 */ 674 */
674 void 675 void
675 buf_freeall(buf_T *buf, int flags) 676 buf_freeall(buf_T *buf, int flags)
676 { 677 {
677 #ifdef FEAT_AUTOCMD 678 #ifdef FEAT_AUTOCMD
678 int is_curbuf = (buf == curbuf); 679 int is_curbuf = (buf == curbuf);
679 bufref_T bufref; 680 bufref_T bufref;
680 681 # ifdef FEAT_WINDOWS
682 int is_curwin = (curwin!= NULL && curwin->w_buffer == buf);
683 win_T *the_curwin = curwin;
684 tabpage_T *the_curtab = curtab;
685 # endif
686
687 /* Make sure the buffer isn't closed by autocommands. */
681 buf->b_closing = TRUE; 688 buf->b_closing = TRUE;
682 set_bufref(&bufref, buf); 689 set_bufref(&bufref, buf);
683 if (buf->b_ml.ml_mfp != NULL) 690 if (buf->b_ml.ml_mfp != NULL)
684 { 691 {
685 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname, 692 if (apply_autocmds(EVENT_BUFUNLOAD, buf->b_fname, buf->b_fname,
703 && !bufref_valid(&bufref)) 710 && !bufref_valid(&bufref))
704 /* autocommands deleted the buffer */ 711 /* autocommands deleted the buffer */
705 return; 712 return;
706 } 713 }
707 buf->b_closing = FALSE; 714 buf->b_closing = FALSE;
715
716 # ifdef FEAT_WINDOWS
717 /* If the buffer was in curwin and the window has changed, go back to that
718 * window, if it still exists. This avoids that ":edit x" triggering a
719 * "tabnext" BufUnload autocmd leaves a window behind without a buffer. */
720 if (is_curwin && curwin != the_curwin && win_valid_any_tab(the_curwin))
721 {
722 block_autocmds();
723 goto_tabpage_win(the_curtab, the_curwin);
724 unblock_autocmds();
725 }
726 # endif
727
708 # ifdef FEAT_EVAL 728 # ifdef FEAT_EVAL
709 if (aborting()) /* autocmds may abort script processing */ 729 if (aborting()) /* autocmds may abort script processing */
710 return; 730 return;
711 # endif 731 # endif
712 732