dcaee6
To: vim_dev@googlegroups.com
dcaee6
Subject: Patch 7.4.082
dcaee6
Fcc: outbox
dcaee6
From: Bram Moolenaar <Bram@moolenaar.net>
dcaee6
Mime-Version: 1.0
dcaee6
Content-Type: text/plain; charset=UTF-8
dcaee6
Content-Transfer-Encoding: 8bit
dcaee6
------------
dcaee6
dcaee6
Patch 7.4.082
dcaee6
Problem:    Using "gf" in a changed buffer suggests adding "!", which is not
dcaee6
            possible. (Tim Chase)
dcaee6
Solution:   Pass a flag to check_changed() wether adding ! make sense.
dcaee6
Files:      src/vim.h, src/ex_cmds2.c, src/proto/ex_cmds2.pro, src/globals.h,
dcaee6
            src/ex_cmds.c, src/ex_docmd.c
dcaee6
dcaee6
dcaee6
*** ../vim-7.4.081/src/vim.h	2013-11-08 04:30:06.000000000 +0100
dcaee6
--- src/vim.h	2013-11-09 03:00:00.000000000 +0100
dcaee6
***************
dcaee6
*** 1176,1181 ****
dcaee6
--- 1176,1190 ----
dcaee6
  #define RESIZE_BOTH	15	/* resize in both directions */
dcaee6
  
dcaee6
  /*
dcaee6
+  * flags for check_changed()
dcaee6
+  */
dcaee6
+ #define CCGD_AW		1	/* do autowrite if buffer was changed */
dcaee6
+ #define CCGD_MULTWIN	2	/* check also when several wins for the buf */
dcaee6
+ #define CCGD_FORCEIT	4	/* ! used */
dcaee6
+ #define CCGD_ALLBUF	8	/* may write all buffers */
dcaee6
+ #define CCGD_EXCMD	16	/* may suggest using ! */
dcaee6
+ 
dcaee6
+ /*
dcaee6
   * "flags" values for option-setting functions.
dcaee6
   * When OPT_GLOBAL and OPT_LOCAL are both missing, set both local and global
dcaee6
   * values, get local value.
dcaee6
*** ../vim-7.4.081/src/ex_cmds2.c	2013-06-28 20:14:53.000000000 +0200
dcaee6
--- src/ex_cmds2.c	2013-11-09 03:14:44.000000000 +0100
dcaee6
***************
dcaee6
*** 1436,1455 ****
dcaee6
  }
dcaee6
  
dcaee6
  /*
dcaee6
!  * return TRUE if buffer was changed and cannot be abandoned.
dcaee6
   */
dcaee6
      int
dcaee6
! check_changed(buf, checkaw, mult_win, forceit, allbuf)
dcaee6
      buf_T	*buf;
dcaee6
!     int		checkaw;	/* do autowrite if buffer was changed */
dcaee6
!     int		mult_win;	/* check also when several wins for the buf */
dcaee6
!     int		forceit;
dcaee6
!     int		allbuf UNUSED;	/* may write all buffers */
dcaee6
  {
dcaee6
      if (       !forceit
dcaee6
  	    && bufIsChanged(buf)
dcaee6
! 	    && (mult_win || buf->b_nwindows <= 1)
dcaee6
! 	    && (!checkaw || autowrite(buf, forceit) == FAIL))
dcaee6
      {
dcaee6
  #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
dcaee6
  	if ((p_confirm || cmdmod.confirm) && p_write)
dcaee6
--- 1436,1455 ----
dcaee6
  }
dcaee6
  
dcaee6
  /*
dcaee6
!  * Return TRUE if buffer was changed and cannot be abandoned.
dcaee6
!  * For flags use the CCGD_ values.
dcaee6
   */
dcaee6
      int
dcaee6
! check_changed(buf, flags)
dcaee6
      buf_T	*buf;
dcaee6
!     int		flags;
dcaee6
  {
dcaee6
+     int forceit = (flags & CCGD_FORCEIT);
dcaee6
+ 
dcaee6
      if (       !forceit
dcaee6
  	    && bufIsChanged(buf)
dcaee6
! 	    && ((flags & CCGD_MULTWIN) || buf->b_nwindows <= 1)
dcaee6
! 	    && (!(flags & CCGD_AW) || autowrite(buf, forceit) == FAIL))
dcaee6
      {
dcaee6
  #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
dcaee6
  	if ((p_confirm || cmdmod.confirm) && p_write)
dcaee6
***************
dcaee6
*** 1457,1463 ****
dcaee6
  	    buf_T	*buf2;
dcaee6
  	    int		count = 0;
dcaee6
  
dcaee6
! 	    if (allbuf)
dcaee6
  		for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
dcaee6
  		    if (bufIsChanged(buf2)
dcaee6
  				     && (buf2->b_ffname != NULL
dcaee6
--- 1457,1463 ----
dcaee6
  	    buf_T	*buf2;
dcaee6
  	    int		count = 0;
dcaee6
  
dcaee6
! 	    if (flags & CCGD_ALLBUF)
dcaee6
  		for (buf2 = firstbuf; buf2 != NULL; buf2 = buf2->b_next)
dcaee6
  		    if (bufIsChanged(buf2)
dcaee6
  				     && (buf2->b_ffname != NULL
dcaee6
***************
dcaee6
*** 1480,1486 ****
dcaee6
  	    return bufIsChanged(buf);
dcaee6
  	}
dcaee6
  #endif
dcaee6
! 	EMSG(_(e_nowrtmsg));
dcaee6
  	return TRUE;
dcaee6
      }
dcaee6
      return FALSE;
dcaee6
--- 1480,1489 ----
dcaee6
  	    return bufIsChanged(buf);
dcaee6
  	}
dcaee6
  #endif
dcaee6
! 	if (flags & CCGD_EXCMD)
dcaee6
! 	    EMSG(_(e_nowrtmsg));
dcaee6
! 	else
dcaee6
! 	    EMSG(_(e_nowrtmsg_nobang));
dcaee6
  	return TRUE;
dcaee6
      }
dcaee6
      return FALSE;
dcaee6
***************
dcaee6
*** 1690,1696 ****
dcaee6
  	{
dcaee6
  	    /* Try auto-writing the buffer.  If this fails but the buffer no
dcaee6
  	    * longer exists it's not changed, that's OK. */
dcaee6
! 	    if (check_changed(buf, p_awa, TRUE, FALSE, TRUE) && buf_valid(buf))
dcaee6
  		break;	    /* didn't save - still changes */
dcaee6
  	}
dcaee6
      }
dcaee6
--- 1693,1701 ----
dcaee6
  	{
dcaee6
  	    /* Try auto-writing the buffer.  If this fails but the buffer no
dcaee6
  	    * longer exists it's not changed, that's OK. */
dcaee6
! 	    if (check_changed(buf, (p_awa ? CCGD_AW : 0)
dcaee6
! 				 | CCGD_MULTWIN
dcaee6
! 				 | CCGD_ALLBUF) && buf_valid(buf))
dcaee6
  		break;	    /* didn't save - still changes */
dcaee6
  	}
dcaee6
      }
dcaee6
***************
dcaee6
*** 2274,2280 ****
dcaee6
  		vim_free(p);
dcaee6
  	    }
dcaee6
  	    if ((!P_HID(curbuf) || !other)
dcaee6
! 		  && check_changed(curbuf, TRUE, !other, eap->forceit, FALSE))
dcaee6
  		return;
dcaee6
  	}
dcaee6
  
dcaee6
--- 2279,2288 ----
dcaee6
  		vim_free(p);
dcaee6
  	    }
dcaee6
  	    if ((!P_HID(curbuf) || !other)
dcaee6
! 		  && check_changed(curbuf, CCGD_AW
dcaee6
! 					 | (other ? 0 : CCGD_MULTWIN)
dcaee6
! 					 | (eap->forceit ? CCGD_FORCEIT : 0)
dcaee6
! 					 | CCGD_EXCMD))
dcaee6
  		return;
dcaee6
  	}
dcaee6
  
dcaee6
***************
dcaee6
*** 2315,2321 ****
dcaee6
       */
dcaee6
      if (       P_HID(curbuf)
dcaee6
  	    || eap->cmdidx == CMD_snext
dcaee6
! 	    || !check_changed(curbuf, TRUE, FALSE, eap->forceit, FALSE))
dcaee6
      {
dcaee6
  	if (*eap->arg != NUL)		    /* redefine file list */
dcaee6
  	{
dcaee6
--- 2323,2331 ----
dcaee6
       */
dcaee6
      if (       P_HID(curbuf)
dcaee6
  	    || eap->cmdidx == CMD_snext
dcaee6
! 	    || !check_changed(curbuf, CCGD_AW
dcaee6
! 				    | (eap->forceit ? CCGD_FORCEIT : 0)
dcaee6
! 				    | CCGD_EXCMD))
dcaee6
      {
dcaee6
  	if (*eap->arg != NUL)		    /* redefine file list */
dcaee6
  	{
dcaee6
***************
dcaee6
*** 2458,2464 ****
dcaee6
      if (eap->cmdidx == CMD_windo
dcaee6
  	    || eap->cmdidx == CMD_tabdo
dcaee6
  	    || P_HID(curbuf)
dcaee6
! 	    || !check_changed(curbuf, TRUE, FALSE, eap->forceit, FALSE))
dcaee6
      {
dcaee6
  	/* start at the first argument/window/buffer */
dcaee6
  	i = 0;
dcaee6
--- 2468,2476 ----
dcaee6
      if (eap->cmdidx == CMD_windo
dcaee6
  	    || eap->cmdidx == CMD_tabdo
dcaee6
  	    || P_HID(curbuf)
dcaee6
! 	    || !check_changed(curbuf, CCGD_AW
dcaee6
! 				    | (eap->forceit ? CCGD_FORCEIT : 0)
dcaee6
! 				    | CCGD_EXCMD))
dcaee6
      {
dcaee6
  	/* start at the first argument/window/buffer */
dcaee6
  	i = 0;
dcaee6
*** ../vim-7.4.081/src/proto/ex_cmds2.pro	2013-08-10 13:37:10.000000000 +0200
dcaee6
--- src/proto/ex_cmds2.pro	2013-11-09 03:18:02.000000000 +0100
dcaee6
***************
dcaee6
*** 35,41 ****
dcaee6
  int prof_def_func __ARGS((void));
dcaee6
  int autowrite __ARGS((buf_T *buf, int forceit));
dcaee6
  void autowrite_all __ARGS((void));
dcaee6
! int check_changed __ARGS((buf_T *buf, int checkaw, int mult_win, int forceit, int allbuf));
dcaee6
  void browse_save_fname __ARGS((buf_T *buf));
dcaee6
  void dialog_changed __ARGS((buf_T *buf, int checkall));
dcaee6
  int can_abandon __ARGS((buf_T *buf, int forceit));
dcaee6
--- 35,41 ----
dcaee6
  int prof_def_func __ARGS((void));
dcaee6
  int autowrite __ARGS((buf_T *buf, int forceit));
dcaee6
  void autowrite_all __ARGS((void));
dcaee6
! int check_changed __ARGS((buf_T *buf, int flags));
dcaee6
  void browse_save_fname __ARGS((buf_T *buf));
dcaee6
  void dialog_changed __ARGS((buf_T *buf, int checkall));
dcaee6
  int can_abandon __ARGS((buf_T *buf, int forceit));
dcaee6
*** ../vim-7.4.081/src/globals.h	2013-07-04 19:53:44.000000000 +0200
dcaee6
--- src/globals.h	2013-11-09 03:05:54.000000000 +0100
dcaee6
***************
dcaee6
*** 1490,1495 ****
dcaee6
--- 1490,1496 ----
dcaee6
  EXTERN char_u e_notopen[]	INIT(= N_("E484: Can't open file %s"));
dcaee6
  EXTERN char_u e_notread[]	INIT(= N_("E485: Can't read file %s"));
dcaee6
  EXTERN char_u e_nowrtmsg[]	INIT(= N_("E37: No write since last change (add ! to override)"));
dcaee6
+ EXTERN char_u e_nowrtmsg_nobang[]   INIT(= N_("E37: No write since last change"));
dcaee6
  EXTERN char_u e_null[]		INIT(= N_("E38: Null argument"));
dcaee6
  #ifdef FEAT_DIGRAPHS
dcaee6
  EXTERN char_u e_number_exp[]	INIT(= N_("E39: Number expected"));
dcaee6
*** ../vim-7.4.081/src/ex_cmds.c	2013-10-02 18:43:00.000000000 +0200
dcaee6
--- src/ex_cmds.c	2013-11-09 03:19:25.000000000 +0100
dcaee6
***************
dcaee6
*** 3253,3260 ****
dcaee6
      if (  ((!other_file && !(flags & ECMD_OLDBUF))
dcaee6
  	    || (curbuf->b_nwindows == 1
dcaee6
  		&& !(flags & (ECMD_HIDE | ECMD_ADDBUF))))
dcaee6
! 	&& check_changed(curbuf, p_awa, !other_file,
dcaee6
! 					(flags & ECMD_FORCEIT), FALSE))
dcaee6
      {
dcaee6
  	if (fnum == 0 && other_file && ffname != NULL)
dcaee6
  	    (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum);
dcaee6
--- 3253,3262 ----
dcaee6
      if (  ((!other_file && !(flags & ECMD_OLDBUF))
dcaee6
  	    || (curbuf->b_nwindows == 1
dcaee6
  		&& !(flags & (ECMD_HIDE | ECMD_ADDBUF))))
dcaee6
! 	&& check_changed(curbuf, (p_awa ? CCGD_AW : 0)
dcaee6
! 			       | (other_file ? 0 : CCGD_MULTWIN)
dcaee6
! 			       | ((flags & ECMD_FORCEIT) ? CCGD_FORCEIT : 0)
dcaee6
! 			       | (eap == NULL ? 0 : CCGD_EXCMD)))
dcaee6
      {
dcaee6
  	if (fnum == 0 && other_file && ffname != NULL)
dcaee6
  	    (void)setaltfname(ffname, sfname, newlnum < 0 ? 0 : newlnum);
dcaee6
***************
dcaee6
*** 7664,7670 ****
dcaee6
  # ifdef FEAT_WINDOWS
dcaee6
  	    ++emsg_off;
dcaee6
  # endif
dcaee6
! 	    split = check_changed(curbuf, TRUE, FALSE, FALSE, FALSE);
dcaee6
  # ifdef FEAT_WINDOWS
dcaee6
  	    --emsg_off;
dcaee6
  # else
dcaee6
--- 7666,7672 ----
dcaee6
  # ifdef FEAT_WINDOWS
dcaee6
  	    ++emsg_off;
dcaee6
  # endif
dcaee6
! 	    split = check_changed(curbuf, CCGD_AW | CCGD_EXCMD);
dcaee6
  # ifdef FEAT_WINDOWS
dcaee6
  	    --emsg_off;
dcaee6
  # else
dcaee6
*** ../vim-7.4.081/src/ex_docmd.c	2013-11-08 04:30:06.000000000 +0100
dcaee6
--- src/ex_docmd.c	2013-11-09 03:30:10.000000000 +0100
dcaee6
***************
dcaee6
*** 6565,6571 ****
dcaee6
      if (check_more(FALSE, eap->forceit) == OK && only_one_window())
dcaee6
  	exiting = TRUE;
dcaee6
      if ((!P_HID(curbuf)
dcaee6
! 		&& check_changed(curbuf, p_awa, FALSE, eap->forceit, FALSE))
dcaee6
  	    || check_more(TRUE, eap->forceit) == FAIL
dcaee6
  	    || (only_one_window() && check_changed_any(eap->forceit)))
dcaee6
      {
dcaee6
--- 6565,6573 ----
dcaee6
      if (check_more(FALSE, eap->forceit) == OK && only_one_window())
dcaee6
  	exiting = TRUE;
dcaee6
      if ((!P_HID(curbuf)
dcaee6
! 		&& check_changed(curbuf, (p_awa ? CCGD_AW : 0)
dcaee6
! 				       | (eap->forceit ? CCGD_FORCEIT : 0)
dcaee6
! 				       | CCGD_EXCMD))
dcaee6
  	    || check_more(TRUE, eap->forceit) == FAIL
dcaee6
  	    || (only_one_window() && check_changed_any(eap->forceit)))
dcaee6
      {
dcaee6
***************
dcaee6
*** 7099,7105 ****
dcaee6
      if (!P_HID(curbuf) && !split)
dcaee6
      {
dcaee6
  	++emsg_off;
dcaee6
! 	split = check_changed(curbuf, TRUE, FALSE, FALSE, FALSE);
dcaee6
  	--emsg_off;
dcaee6
      }
dcaee6
      if (split)
dcaee6
--- 7101,7107 ----
dcaee6
      if (!P_HID(curbuf) && !split)
dcaee6
      {
dcaee6
  	++emsg_off;
dcaee6
! 	split = check_changed(curbuf, CCGD_AW);
dcaee6
  	--emsg_off;
dcaee6
      }
dcaee6
      if (split)
dcaee6
***************
dcaee6
*** 7361,7367 ****
dcaee6
  {
dcaee6
      /* Set recoverymode right away to avoid the ATTENTION prompt. */
dcaee6
      recoverymode = TRUE;
dcaee6
!     if (!check_changed(curbuf, p_awa, TRUE, eap->forceit, FALSE)
dcaee6
  	    && (*eap->arg == NUL
dcaee6
  			     || setfname(curbuf, eap->arg, NULL, TRUE) == OK))
dcaee6
  	ml_recover();
dcaee6
--- 7363,7373 ----
dcaee6
  {
dcaee6
      /* Set recoverymode right away to avoid the ATTENTION prompt. */
dcaee6
      recoverymode = TRUE;
dcaee6
!     if (!check_changed(curbuf, (p_awa ? CCGD_AW : 0)
dcaee6
! 			     | CCGD_MULTWIN
dcaee6
! 			     | (eap->forceit ? CCGD_FORCEIT : 0)
dcaee6
! 			     | CCGD_EXCMD)
dcaee6
! 
dcaee6
  	    && (*eap->arg == NUL
dcaee6
  			     || setfname(curbuf, eap->arg, NULL, TRUE) == OK))
dcaee6
  	ml_recover();
dcaee6
*** ../vim-7.4.081/src/version.c	2013-11-09 02:32:15.000000000 +0100
dcaee6
--- src/version.c	2013-11-09 03:26:06.000000000 +0100
dcaee6
***************
dcaee6
*** 740,741 ****
dcaee6
--- 740,743 ----
dcaee6
  {   /* Add new patch number below this line */
dcaee6
+ /**/
dcaee6
+     82,
dcaee6
  /**/
dcaee6
dcaee6
-- 
dcaee6
People who want to share their religious views with you
dcaee6
almost never want you to share yours with them.
dcaee6
dcaee6
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
dcaee6
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
dcaee6
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
dcaee6
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///