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