3ef2ca
To: vim_dev@googlegroups.com
3ef2ca
Subject: Patch 7.4.140
3ef2ca
Fcc: outbox
3ef2ca
From: Bram Moolenaar <Bram@moolenaar.net>
3ef2ca
Mime-Version: 1.0
3ef2ca
Content-Type: text/plain; charset=UTF-8
3ef2ca
Content-Transfer-Encoding: 8bit
3ef2ca
------------
3ef2ca
3ef2ca
Patch 7.4.140
3ef2ca
Problem:    Crash when wiping out buffer triggers autocommand that wipes out
3ef2ca
	    only other buffer.
3ef2ca
Solution:   Do not delete the last buffer, make it empty. (Hirohito Higashi)
3ef2ca
Files:	    src/buffer.c
3ef2ca
3ef2ca
3ef2ca
*** ../vim-7.4.139/src/buffer.c	2013-11-06 05:26:08.000000000 +0100
3ef2ca
--- src/buffer.c	2014-01-10 16:41:22.000000000 +0100
3ef2ca
***************
3ef2ca
*** 994,999 ****
3ef2ca
--- 994,1043 ----
3ef2ca
  #if defined(FEAT_LISTCMDS) || defined(FEAT_PYTHON) \
3ef2ca
  	|| defined(FEAT_PYTHON3) || defined(PROTO)
3ef2ca
  
3ef2ca
+ static int	empty_curbuf __ARGS((int close_others, int forceit, int action));
3ef2ca
+ 
3ef2ca
+ /*
3ef2ca
+  * Make the current buffer empty.
3ef2ca
+  * Used when it is wiped out and it's the last buffer.
3ef2ca
+  */
3ef2ca
+     static int
3ef2ca
+ empty_curbuf(close_others, forceit, action)
3ef2ca
+     int close_others;
3ef2ca
+     int forceit;
3ef2ca
+     int action;
3ef2ca
+ {
3ef2ca
+     int	    retval;
3ef2ca
+     buf_T   *buf = curbuf;
3ef2ca
+ 
3ef2ca
+     if (action == DOBUF_UNLOAD)
3ef2ca
+     {
3ef2ca
+ 	EMSG(_("E90: Cannot unload last buffer"));
3ef2ca
+ 	return FAIL;
3ef2ca
+     }
3ef2ca
+ 
3ef2ca
+     if (close_others)
3ef2ca
+     {
3ef2ca
+ 	/* Close any other windows on this buffer, then make it empty. */
3ef2ca
+ #ifdef FEAT_WINDOWS
3ef2ca
+ 	close_windows(buf, TRUE);
3ef2ca
+ #endif
3ef2ca
+     }
3ef2ca
+ 
3ef2ca
+     setpcmark();
3ef2ca
+     retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
3ef2ca
+ 					  forceit ? ECMD_FORCEIT : 0, curwin);
3ef2ca
+ 
3ef2ca
+     /*
3ef2ca
+      * do_ecmd() may create a new buffer, then we have to delete
3ef2ca
+      * the old one.  But do_ecmd() may have done that already, check
3ef2ca
+      * if the buffer still exists.
3ef2ca
+      */
3ef2ca
+     if (buf != curbuf && buf_valid(buf) && buf->b_nwindows == 0)
3ef2ca
+ 	close_buffer(NULL, buf, action, FALSE);
3ef2ca
+     if (!close_others)
3ef2ca
+ 	need_fileinfo = FALSE;
3ef2ca
+     return retval;
3ef2ca
+ }
3ef2ca
  /*
3ef2ca
   * Implementation of the commands for the buffer list.
3ef2ca
   *
3ef2ca
***************
3ef2ca
*** 1114,1120 ****
3ef2ca
      if (unload)
3ef2ca
      {
3ef2ca
  	int	forward;
3ef2ca
- 	int	retval;
3ef2ca
  
3ef2ca
  	/* When unloading or deleting a buffer that's already unloaded and
3ef2ca
  	 * unlisted: fail silently. */
3ef2ca
--- 1158,1163 ----
3ef2ca
***************
3ef2ca
*** 1155,1184 ****
3ef2ca
  	    if (bp->b_p_bl && bp != buf)
3ef2ca
  		break;
3ef2ca
  	if (bp == NULL && buf == curbuf)
3ef2ca
! 	{
3ef2ca
! 	    if (action == DOBUF_UNLOAD)
3ef2ca
! 	    {
3ef2ca
! 		EMSG(_("E90: Cannot unload last buffer"));
3ef2ca
! 		return FAIL;
3ef2ca
! 	    }
3ef2ca
! 
3ef2ca
! 	    /* Close any other windows on this buffer, then make it empty. */
3ef2ca
! #ifdef FEAT_WINDOWS
3ef2ca
! 	    close_windows(buf, TRUE);
3ef2ca
! #endif
3ef2ca
! 	    setpcmark();
3ef2ca
! 	    retval = do_ecmd(0, NULL, NULL, NULL, ECMD_ONE,
3ef2ca
! 					  forceit ? ECMD_FORCEIT : 0, curwin);
3ef2ca
! 
3ef2ca
! 	    /*
3ef2ca
! 	     * do_ecmd() may create a new buffer, then we have to delete
3ef2ca
! 	     * the old one.  But do_ecmd() may have done that already, check
3ef2ca
! 	     * if the buffer still exists.
3ef2ca
! 	     */
3ef2ca
! 	    if (buf != curbuf && buf_valid(buf) && buf->b_nwindows == 0)
3ef2ca
! 		close_buffer(NULL, buf, action, FALSE);
3ef2ca
! 	    return retval;
3ef2ca
! 	}
3ef2ca
  
3ef2ca
  #ifdef FEAT_WINDOWS
3ef2ca
  	/*
3ef2ca
--- 1198,1204 ----
3ef2ca
  	    if (bp->b_p_bl && bp != buf)
3ef2ca
  		break;
3ef2ca
  	if (bp == NULL && buf == curbuf)
3ef2ca
! 	    return empty_curbuf(TRUE, forceit, action);
3ef2ca
  
3ef2ca
  #ifdef FEAT_WINDOWS
3ef2ca
  	/*
3ef2ca
***************
3ef2ca
*** 1212,1218 ****
3ef2ca
  
3ef2ca
  	/*
3ef2ca
  	 * Deleting the current buffer: Need to find another buffer to go to.
3ef2ca
! 	 * There must be another, otherwise it would have been handled above.
3ef2ca
  	 * First use au_new_curbuf, if it is valid.
3ef2ca
  	 * Then prefer the buffer we most recently visited.
3ef2ca
  	 * Else try to find one that is loaded, after the current buffer,
3ef2ca
--- 1232,1239 ----
3ef2ca
  
3ef2ca
  	/*
3ef2ca
  	 * Deleting the current buffer: Need to find another buffer to go to.
3ef2ca
! 	 * There should be another, otherwise it would have been handled
3ef2ca
! 	 * above.  However, autocommands may have deleted all buffers.
3ef2ca
  	 * First use au_new_curbuf, if it is valid.
3ef2ca
  	 * Then prefer the buffer we most recently visited.
3ef2ca
  	 * Else try to find one that is loaded, after the current buffer,
3ef2ca
***************
3ef2ca
*** 1311,1316 ****
3ef2ca
--- 1332,1344 ----
3ef2ca
  	}
3ef2ca
      }
3ef2ca
  
3ef2ca
+     if (buf == NULL)
3ef2ca
+     {
3ef2ca
+ 	/* Autocommands must have wiped out all other buffers.  Only option
3ef2ca
+ 	 * now is to make the current buffer empty. */
3ef2ca
+ 	return empty_curbuf(FALSE, forceit, action);
3ef2ca
+     }
3ef2ca
+ 
3ef2ca
      /*
3ef2ca
       * make buf current buffer
3ef2ca
       */
3ef2ca
*** ../vim-7.4.139/src/version.c	2014-01-10 15:53:09.000000000 +0100
3ef2ca
--- src/version.c	2014-01-10 16:36:03.000000000 +0100
3ef2ca
***************
3ef2ca
*** 740,741 ****
3ef2ca
--- 740,743 ----
3ef2ca
  {   /* Add new patch number below this line */
3ef2ca
+ /**/
3ef2ca
+     140,
3ef2ca
  /**/
3ef2ca
3ef2ca
-- 
3ef2ca
hundred-and-one symptoms of being an internet addict:
3ef2ca
133. You communicate with people on other continents more than you
3ef2ca
     do with your own neighbors.
3ef2ca
3ef2ca
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
3ef2ca
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
3ef2ca
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
3ef2ca
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///