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