Blame SOURCES/7.4.004

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.004
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.004
22c937
Problem:    When closing a window fails ":bwipe" may hang.
22c937
Solution:   Let win_close() return FAIL and break out of the loop.
22c937
Files:	    src/window.c, src/proto/window.pro, src/buffer.c
22c937
22c937
22c937
*** ../vim-7.4.003/src/window.c	2013-07-24 17:38:29.000000000 +0200
22c937
--- src/window.c	2013-08-14 16:52:44.000000000 +0200
22c937
***************
22c937
*** 2172,2179 ****
22c937
   * If "free_buf" is TRUE related buffer may be unloaded.
22c937
   *
22c937
   * Called by :quit, :close, :xit, :wq and findtag().
22c937
   */
22c937
!     void
22c937
  win_close(win, free_buf)
22c937
      win_T	*win;
22c937
      int		free_buf;
22c937
--- 2172,2180 ----
22c937
   * If "free_buf" is TRUE related buffer may be unloaded.
22c937
   *
22c937
   * Called by :quit, :close, :xit, :wq and findtag().
22c937
+  * Returns FAIL when the window was not closed.
22c937
   */
22c937
!     int
22c937
  win_close(win, free_buf)
22c937
      win_T	*win;
22c937
      int		free_buf;
22c937
***************
22c937
*** 2190,2210 ****
22c937
      if (last_window())
22c937
      {
22c937
  	EMSG(_("E444: Cannot close last window"));
22c937
! 	return;
22c937
      }
22c937
  
22c937
  #ifdef FEAT_AUTOCMD
22c937
      if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_closing))
22c937
! 	return; /* window is already being closed */
22c937
      if (win == aucmd_win)
22c937
      {
22c937
  	EMSG(_("E813: Cannot close autocmd window"));
22c937
! 	return;
22c937
      }
22c937
      if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window())
22c937
      {
22c937
  	EMSG(_("E814: Cannot close window, only autocmd window would remain"));
22c937
! 	return;
22c937
      }
22c937
  #endif
22c937
  
22c937
--- 2191,2211 ----
22c937
      if (last_window())
22c937
      {
22c937
  	EMSG(_("E444: Cannot close last window"));
22c937
! 	return FAIL;
22c937
      }
22c937
  
22c937
  #ifdef FEAT_AUTOCMD
22c937
      if (win->w_closing || (win->w_buffer != NULL && win->w_buffer->b_closing))
22c937
! 	return FAIL; /* window is already being closed */
22c937
      if (win == aucmd_win)
22c937
      {
22c937
  	EMSG(_("E813: Cannot close autocmd window"));
22c937
! 	return FAIL;
22c937
      }
22c937
      if ((firstwin == aucmd_win || lastwin == aucmd_win) && one_window())
22c937
      {
22c937
  	EMSG(_("E814: Cannot close window, only autocmd window would remain"));
22c937
! 	return FAIL;
22c937
      }
22c937
  #endif
22c937
  
22c937
***************
22c937
*** 2212,2218 ****
22c937
       * and then close the window and the tab page to avoid that curwin and
22c937
       * curtab are invalid while we are freeing memory. */
22c937
      if (close_last_window_tabpage(win, free_buf, prev_curtab))
22c937
!       return;
22c937
  
22c937
      /* When closing the help window, try restoring a snapshot after closing
22c937
       * the window.  Otherwise clear the snapshot, it's now invalid. */
22c937
--- 2213,2219 ----
22c937
       * and then close the window and the tab page to avoid that curwin and
22c937
       * curtab are invalid while we are freeing memory. */
22c937
      if (close_last_window_tabpage(win, free_buf, prev_curtab))
22c937
!       return FAIL;
22c937
  
22c937
      /* When closing the help window, try restoring a snapshot after closing
22c937
       * the window.  Otherwise clear the snapshot, it's now invalid. */
22c937
***************
22c937
*** 2240,2261 ****
22c937
  	    win->w_closing = TRUE;
22c937
  	    apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
22c937
  	    if (!win_valid(win))
22c937
! 		return;
22c937
  	    win->w_closing = FALSE;
22c937
  	    if (last_window())
22c937
! 		return;
22c937
  	}
22c937
  	win->w_closing = TRUE;
22c937
  	apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
22c937
  	if (!win_valid(win))
22c937
! 	    return;
22c937
  	win->w_closing = FALSE;
22c937
  	if (last_window())
22c937
! 	    return;
22c937
  # ifdef FEAT_EVAL
22c937
  	/* autocmds may abort script processing */
22c937
  	if (aborting())
22c937
! 	    return;
22c937
  # endif
22c937
      }
22c937
  #endif
22c937
--- 2241,2262 ----
22c937
  	    win->w_closing = TRUE;
22c937
  	    apply_autocmds(EVENT_BUFLEAVE, NULL, NULL, FALSE, curbuf);
22c937
  	    if (!win_valid(win))
22c937
! 		return FAIL;
22c937
  	    win->w_closing = FALSE;
22c937
  	    if (last_window())
22c937
! 		return FAIL;
22c937
  	}
22c937
  	win->w_closing = TRUE;
22c937
  	apply_autocmds(EVENT_WINLEAVE, NULL, NULL, FALSE, curbuf);
22c937
  	if (!win_valid(win))
22c937
! 	    return FAIL;
22c937
  	win->w_closing = FALSE;
22c937
  	if (last_window())
22c937
! 	    return FAIL;
22c937
  # ifdef FEAT_EVAL
22c937
  	/* autocmds may abort script processing */
22c937
  	if (aborting())
22c937
! 	    return FAIL;
22c937
  # endif
22c937
      }
22c937
  #endif
22c937
***************
22c937
*** 2303,2309 ****
22c937
       * other window or moved to another tab page. */
22c937
      else if (!win_valid(win) || last_window() || curtab != prev_curtab
22c937
  	    || close_last_window_tabpage(win, free_buf, prev_curtab))
22c937
! 	return;
22c937
  
22c937
      /* Free the memory used for the window and get the window that received
22c937
       * the screen space. */
22c937
--- 2304,2310 ----
22c937
       * other window or moved to another tab page. */
22c937
      else if (!win_valid(win) || last_window() || curtab != prev_curtab
22c937
  	    || close_last_window_tabpage(win, free_buf, prev_curtab))
22c937
! 	return FAIL;
22c937
  
22c937
      /* Free the memory used for the window and get the window that received
22c937
       * the screen space. */
22c937
***************
22c937
*** 2383,2388 ****
22c937
--- 2384,2390 ----
22c937
  #endif
22c937
  
22c937
      redraw_all_later(NOT_VALID);
22c937
+     return OK;
22c937
  }
22c937
  
22c937
  /*
22c937
*** ../vim-7.4.003/src/proto/window.pro	2013-08-10 13:37:30.000000000 +0200
22c937
--- src/proto/window.pro	2013-08-14 16:52:50.000000000 +0200
22c937
***************
22c937
*** 9,15 ****
22c937
  void win_equal __ARGS((win_T *next_curwin, int current, int dir));
22c937
  void close_windows __ARGS((buf_T *buf, int keep_curwin));
22c937
  int one_window __ARGS((void));
22c937
! void win_close __ARGS((win_T *win, int free_buf));
22c937
  void win_close_othertab __ARGS((win_T *win, int free_buf, tabpage_T *tp));
22c937
  void win_free_all __ARGS((void));
22c937
  win_T *winframe_remove __ARGS((win_T *win, int *dirp, tabpage_T *tp));
22c937
--- 9,15 ----
22c937
  void win_equal __ARGS((win_T *next_curwin, int current, int dir));
22c937
  void close_windows __ARGS((buf_T *buf, int keep_curwin));
22c937
  int one_window __ARGS((void));
22c937
! int win_close __ARGS((win_T *win, int free_buf));
22c937
  void win_close_othertab __ARGS((win_T *win, int free_buf, tabpage_T *tp));
22c937
  void win_free_all __ARGS((void));
22c937
  win_T *winframe_remove __ARGS((win_T *win, int *dirp, tabpage_T *tp));
22c937
*** ../vim-7.4.003/src/buffer.c	2013-07-17 16:39:00.000000000 +0200
22c937
--- src/buffer.c	2013-08-14 16:54:34.000000000 +0200
22c937
***************
22c937
*** 1186,1192 ****
22c937
  		   && !(curwin->w_closing || curwin->w_buffer->b_closing)
22c937
  # endif
22c937
  		   && (firstwin != lastwin || first_tabpage->tp_next != NULL))
22c937
! 	    win_close(curwin, FALSE);
22c937
  #endif
22c937
  
22c937
  	/*
22c937
--- 1186,1195 ----
22c937
  		   && !(curwin->w_closing || curwin->w_buffer->b_closing)
22c937
  # endif
22c937
  		   && (firstwin != lastwin || first_tabpage->tp_next != NULL))
22c937
! 	{
22c937
! 	    if (win_close(curwin, FALSE) == FAIL)
22c937
! 		break;
22c937
! 	}
22c937
  #endif
22c937
  
22c937
  	/*
22c937
*** ../vim-7.4.003/src/version.c	2013-08-14 14:18:37.000000000 +0200
22c937
--- src/version.c	2013-08-14 17:10:23.000000000 +0200
22c937
***************
22c937
*** 729,730 ****
22c937
--- 729,732 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     4,
22c937
  /**/
22c937
22c937
-- 
22c937
From "know your smileys":
22c937
 *<|:-)	Santa Claus (Ho Ho Ho)
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///