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