Karsten Hopp a33f25
To: vim_dev@googlegroups.com
Karsten Hopp a33f25
Subject: Patch 7.3.480
Karsten Hopp a33f25
Fcc: outbox
Karsten Hopp a33f25
From: Bram Moolenaar <Bram@moolenaar.net>
Karsten Hopp a33f25
Mime-Version: 1.0
Karsten Hopp a33f25
Content-Type: text/plain; charset=UTF-8
Karsten Hopp a33f25
Content-Transfer-Encoding: 8bit
Karsten Hopp a33f25
------------
Karsten Hopp a33f25
Karsten Hopp a33f25
Patch 7.3.480
Karsten Hopp a33f25
Problem:    When using ":qa" and there is a changed buffer picking the buffer
Karsten Hopp a33f25
	    to jump to is not very good.
Karsten Hopp a33f25
Solution:   Consider current and other tab pages. (Hirohito Higashi)
Karsten Hopp a33f25
Files:	    src/ex_cmds2.c
Karsten Hopp a33f25
Karsten Hopp a33f25
Karsten Hopp a33f25
*** ../vim-7.3.479/src/ex_cmds2.c	2012-02-22 18:29:29.000000000 +0100
Karsten Hopp a33f25
--- src/ex_cmds2.c	2012-03-23 17:01:31.000000000 +0100
Karsten Hopp a33f25
***************
Karsten Hopp a33f25
*** 1569,1574 ****
Karsten Hopp a33f25
--- 1569,1594 ----
Karsten Hopp a33f25
  		|| forceit);
Karsten Hopp a33f25
  }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
+ static void add_bufnum __ARGS((int *bufnrs, int *bufnump, int nr));
Karsten Hopp a33f25
+ 
Karsten Hopp a33f25
+ /*
Karsten Hopp a33f25
+  * Add a buffer number to "bufnrs", unless it's already there.
Karsten Hopp a33f25
+  */
Karsten Hopp a33f25
+     static void
Karsten Hopp a33f25
+ add_bufnum(bufnrs, bufnump, nr)
Karsten Hopp a33f25
+     int	    *bufnrs;
Karsten Hopp a33f25
+     int	    *bufnump;
Karsten Hopp a33f25
+     int	    nr;
Karsten Hopp a33f25
+ {
Karsten Hopp a33f25
+     int i;
Karsten Hopp a33f25
+ 
Karsten Hopp a33f25
+     for (i = 0; i < *bufnump; ++i)
Karsten Hopp a33f25
+ 	if (bufnrs[i] == nr)
Karsten Hopp a33f25
+ 	    return;
Karsten Hopp a33f25
+     bufnrs[*bufnump] = nr;
Karsten Hopp a33f25
+     *bufnump = *bufnump + 1;
Karsten Hopp a33f25
+ }
Karsten Hopp a33f25
+ 
Karsten Hopp a33f25
  /*
Karsten Hopp a33f25
   * Return TRUE if any buffer was changed and cannot be abandoned.
Karsten Hopp a33f25
   * That changed buffer becomes the current buffer.
Karsten Hopp a33f25
***************
Karsten Hopp a33f25
*** 1577,1608 ****
Karsten Hopp a33f25
  check_changed_any(hidden)
Karsten Hopp a33f25
      int		hidden;		/* Only check hidden buffers */
Karsten Hopp a33f25
  {
Karsten Hopp a33f25
      buf_T	*buf;
Karsten Hopp a33f25
      int		save;
Karsten Hopp a33f25
  #ifdef FEAT_WINDOWS
Karsten Hopp a33f25
      win_T	*wp;
Karsten Hopp a33f25
  #endif
Karsten Hopp a33f25
  
Karsten Hopp a33f25
!     for (;;)
Karsten Hopp a33f25
      {
Karsten Hopp a33f25
! 	/* check curbuf first: if it was changed we can't abandon it */
Karsten Hopp a33f25
! 	if (!hidden && curbufIsChanged())
Karsten Hopp a33f25
! 	    buf = curbuf;
Karsten Hopp a33f25
! 	else
Karsten Hopp a33f25
  	{
Karsten Hopp a33f25
! 	    for (buf = firstbuf; buf != NULL; buf = buf->b_next)
Karsten Hopp a33f25
! 		if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf))
Karsten Hopp a33f25
! 		    break;
Karsten Hopp a33f25
  	}
Karsten Hopp a33f25
- 	if (buf == NULL)    /* No buffers changed */
Karsten Hopp a33f25
- 	    return FALSE;
Karsten Hopp a33f25
- 
Karsten Hopp a33f25
- 	/* Try auto-writing the buffer.  If this fails but the buffer no
Karsten Hopp a33f25
- 	 * longer exists it's not changed, that's OK. */
Karsten Hopp a33f25
- 	if (check_changed(buf, p_awa, TRUE, FALSE, TRUE) && buf_valid(buf))
Karsten Hopp a33f25
- 	    break;	    /* didn't save - still changes */
Karsten Hopp a33f25
      }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
      exiting = FALSE;
Karsten Hopp a33f25
  #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
Karsten Hopp a33f25
      /*
Karsten Hopp a33f25
--- 1597,1660 ----
Karsten Hopp a33f25
  check_changed_any(hidden)
Karsten Hopp a33f25
      int		hidden;		/* Only check hidden buffers */
Karsten Hopp a33f25
  {
Karsten Hopp a33f25
+     int		ret = FALSE;
Karsten Hopp a33f25
      buf_T	*buf;
Karsten Hopp a33f25
      int		save;
Karsten Hopp a33f25
+     int		i;
Karsten Hopp a33f25
+     int		bufnum = 0;
Karsten Hopp a33f25
+     int		bufcount = 0;
Karsten Hopp a33f25
+     int		*bufnrs;
Karsten Hopp a33f25
  #ifdef FEAT_WINDOWS
Karsten Hopp a33f25
+     tabpage_T   *tp;
Karsten Hopp a33f25
      win_T	*wp;
Karsten Hopp a33f25
  #endif
Karsten Hopp a33f25
  
Karsten Hopp a33f25
!     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
Karsten Hopp a33f25
! 	++bufcount;
Karsten Hopp a33f25
! 
Karsten Hopp a33f25
!     if (bufcount == 0)
Karsten Hopp a33f25
! 	return FALSE;
Karsten Hopp a33f25
! 
Karsten Hopp a33f25
!     bufnrs = (int *)alloc(sizeof(int) * bufcount);
Karsten Hopp a33f25
!     if (bufnrs == NULL)
Karsten Hopp a33f25
! 	return FALSE;
Karsten Hopp a33f25
! 
Karsten Hopp a33f25
!     /* curbuf */
Karsten Hopp a33f25
!     bufnrs[bufnum++] = curbuf->b_fnum;
Karsten Hopp a33f25
! #ifdef FEAT_WINDOWS
Karsten Hopp a33f25
!     /* buf in curtab */
Karsten Hopp a33f25
!     FOR_ALL_WINDOWS(wp)
Karsten Hopp a33f25
! 	if (wp->w_buffer != curbuf)
Karsten Hopp a33f25
! 	    add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
Karsten Hopp a33f25
! 
Karsten Hopp a33f25
!     /* buf in other tab */
Karsten Hopp a33f25
!     for (tp = first_tabpage; tp != NULL; tp = tp->tp_next)
Karsten Hopp a33f25
! 	if (tp != curtab)
Karsten Hopp a33f25
! 	    for (wp = tp->tp_firstwin; wp != NULL; wp = wp->w_next)
Karsten Hopp a33f25
! 		add_bufnum(bufnrs, &bufnum, wp->w_buffer->b_fnum);
Karsten Hopp a33f25
! #endif
Karsten Hopp a33f25
!     /* any other buf */
Karsten Hopp a33f25
!     for (buf = firstbuf; buf != NULL; buf = buf->b_next)
Karsten Hopp a33f25
! 	add_bufnum(bufnrs, &bufnum, buf->b_fnum);
Karsten Hopp a33f25
! 
Karsten Hopp a33f25
!     for (i = 0; i < bufnum; ++i)
Karsten Hopp a33f25
      {
Karsten Hopp a33f25
! 	buf = buflist_findnr(bufnrs[i]);
Karsten Hopp a33f25
! 	if (buf == NULL)
Karsten Hopp a33f25
! 	    continue;
Karsten Hopp a33f25
! 	if ((!hidden || buf->b_nwindows == 0) && bufIsChanged(buf))
Karsten Hopp a33f25
  	{
Karsten Hopp a33f25
! 	    /* Try auto-writing the buffer.  If this fails but the buffer no
Karsten Hopp a33f25
! 	    * longer exists it's not changed, that's OK. */
Karsten Hopp a33f25
! 	    if (check_changed(buf, p_awa, TRUE, FALSE, TRUE) && buf_valid(buf))
Karsten Hopp a33f25
! 		break;	    /* didn't save - still changes */
Karsten Hopp a33f25
  	}
Karsten Hopp a33f25
      }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
+     if (i >= bufnum)
Karsten Hopp a33f25
+ 	goto theend;
Karsten Hopp a33f25
+ 
Karsten Hopp a33f25
+     ret = TRUE;
Karsten Hopp a33f25
      exiting = FALSE;
Karsten Hopp a33f25
  #if defined(FEAT_GUI_DIALOG) || defined(FEAT_CON_DIALOG)
Karsten Hopp a33f25
      /*
Karsten Hopp a33f25
***************
Karsten Hopp a33f25
*** 1635,1658 ****
Karsten Hopp a33f25
  #ifdef FEAT_WINDOWS
Karsten Hopp a33f25
      /* Try to find a window that contains the buffer. */
Karsten Hopp a33f25
      if (buf != curbuf)
Karsten Hopp a33f25
! 	for (wp = firstwin; wp != NULL; wp = wp->w_next)
Karsten Hopp a33f25
  	    if (wp->w_buffer == buf)
Karsten Hopp a33f25
  	    {
Karsten Hopp a33f25
! 		win_goto(wp);
Karsten Hopp a33f25
  # ifdef FEAT_AUTOCMD
Karsten Hopp a33f25
  		/* Paranoia: did autocms wipe out the buffer with changes? */
Karsten Hopp a33f25
  		if (!buf_valid(buf))
Karsten Hopp a33f25
! 		    return TRUE;
Karsten Hopp a33f25
  # endif
Karsten Hopp a33f25
! 		break;
Karsten Hopp a33f25
  	    }
Karsten Hopp a33f25
  #endif
Karsten Hopp a33f25
  
Karsten Hopp a33f25
      /* Open the changed buffer in the current window. */
Karsten Hopp a33f25
      if (buf != curbuf)
Karsten Hopp a33f25
  	set_curbuf(buf, DOBUF_GOTO);
Karsten Hopp a33f25
  
Karsten Hopp a33f25
!     return TRUE;
Karsten Hopp a33f25
  }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
  /*
Karsten Hopp a33f25
--- 1687,1715 ----
Karsten Hopp a33f25
  #ifdef FEAT_WINDOWS
Karsten Hopp a33f25
      /* Try to find a window that contains the buffer. */
Karsten Hopp a33f25
      if (buf != curbuf)
Karsten Hopp a33f25
! 	FOR_ALL_TAB_WINDOWS(tp, wp)
Karsten Hopp a33f25
  	    if (wp->w_buffer == buf)
Karsten Hopp a33f25
  	    {
Karsten Hopp a33f25
! 		goto_tabpage_win(tp, wp);
Karsten Hopp a33f25
  # ifdef FEAT_AUTOCMD
Karsten Hopp a33f25
  		/* Paranoia: did autocms wipe out the buffer with changes? */
Karsten Hopp a33f25
  		if (!buf_valid(buf))
Karsten Hopp a33f25
! 		{
Karsten Hopp a33f25
! 		    goto theend;
Karsten Hopp a33f25
! 		}
Karsten Hopp a33f25
  # endif
Karsten Hopp a33f25
! 		goto buf_found;
Karsten Hopp a33f25
  	    }
Karsten Hopp a33f25
+ buf_found:
Karsten Hopp a33f25
  #endif
Karsten Hopp a33f25
  
Karsten Hopp a33f25
      /* Open the changed buffer in the current window. */
Karsten Hopp a33f25
      if (buf != curbuf)
Karsten Hopp a33f25
  	set_curbuf(buf, DOBUF_GOTO);
Karsten Hopp a33f25
  
Karsten Hopp a33f25
! theend:
Karsten Hopp a33f25
!     vim_free(bufnrs);
Karsten Hopp a33f25
!     return ret;
Karsten Hopp a33f25
  }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
  /*
Karsten Hopp a33f25
***************
Karsten Hopp a33f25
*** 3274,3280 ****
Karsten Hopp a33f25
  	    home_replace(NULL, SCRIPT_ITEM(i).sn_name,
Karsten Hopp a33f25
  						    NameBuff, MAXPATHL, TRUE);
Karsten Hopp a33f25
  	    smsg((char_u *)"%3d: %s", i, NameBuff);
Karsten Hopp a33f25
!         }
Karsten Hopp a33f25
  }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
  # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
Karsten Hopp a33f25
--- 3331,3337 ----
Karsten Hopp a33f25
  	    home_replace(NULL, SCRIPT_ITEM(i).sn_name,
Karsten Hopp a33f25
  						    NameBuff, MAXPATHL, TRUE);
Karsten Hopp a33f25
  	    smsg((char_u *)"%3d: %s", i, NameBuff);
Karsten Hopp a33f25
! 	}
Karsten Hopp a33f25
  }
Karsten Hopp a33f25
  
Karsten Hopp a33f25
  # if defined(BACKSLASH_IN_FILENAME) || defined(PROTO)
Karsten Hopp a33f25
*** ../vim-7.3.479/src/version.c	2012-03-23 16:25:13.000000000 +0100
Karsten Hopp a33f25
--- src/version.c	2012-03-23 16:48:06.000000000 +0100
Karsten Hopp a33f25
***************
Karsten Hopp a33f25
*** 716,717 ****
Karsten Hopp a33f25
--- 716,719 ----
Karsten Hopp a33f25
  {   /* Add new patch number below this line */
Karsten Hopp a33f25
+ /**/
Karsten Hopp a33f25
+     480,
Karsten Hopp a33f25
  /**/
Karsten Hopp a33f25
Karsten Hopp a33f25
-- 
Karsten Hopp a33f25
hundred-and-one symptoms of being an internet addict:
Karsten Hopp a33f25
243. You unsuccessfully try to download a pizza from www.dominos.com.
Karsten Hopp a33f25
Karsten Hopp a33f25
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
Karsten Hopp a33f25
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
Karsten Hopp a33f25
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
Karsten Hopp a33f25
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///