073263
To: vim_dev@googlegroups.com
073263
Subject: Patch 7.4.603
073263
Fcc: outbox
073263
From: Bram Moolenaar <Bram@moolenaar.net>
073263
Mime-Version: 1.0
073263
Content-Type: text/plain; charset=UTF-8
073263
Content-Transfer-Encoding: 8bit
073263
------------
073263
073263
Patch 7.4.603
073263
Problem:    'foldcolumn' may be set such that it fills the whole window, not
073263
	    leaving space for text.
073263
Solution:   Reduce the foldcolumn width when there is not sufficient room.
073263
	    (idea by Christian Brabandt)
073263
Files:	    src/srcreen.c
073263
073263
073263
*** ../vim-7.4.602/src/screen.c	2015-01-20 19:01:32.380444290 +0100
073263
--- src/screen.c	2015-01-27 16:25:47.264690419 +0100
073263
***************
073263
*** 109,114 ****
073263
--- 109,115 ----
073263
  
073263
  #ifdef FEAT_FOLDING
073263
  static foldinfo_T win_foldinfo;	/* info for 'foldcolumn' */
073263
+ static int compute_foldcolumn __ARGS((win_T *wp, int col));
073263
  #endif
073263
  
073263
  /*
073263
***************
073263
*** 1202,1208 ****
073263
  			lnumb = wp->w_lines[i].wl_lnum;
073263
  			/* When there is a fold column it might need updating
073263
  			 * in the next line ("J" just above an open fold). */
073263
! 			if (wp->w_p_fdc > 0)
073263
  			    ++lnumb;
073263
  		    }
073263
  		}
073263
--- 1203,1209 ----
073263
  			lnumb = wp->w_lines[i].wl_lnum;
073263
  			/* When there is a fold column it might need updating
073263
  			 * in the next line ("J" just above an open fold). */
073263
! 			if (compute_foldcolumn(wp, 0) > 0)
073263
  			    ++lnumb;
073263
  		    }
073263
  		}
073263
***************
073263
*** 2238,2250 ****
073263
  #else
073263
  # define FDC_OFF 0
073263
  #endif
073263
  
073263
  #ifdef FEAT_RIGHTLEFT
073263
      if (wp->w_p_rl)
073263
      {
073263
  	/* No check for cmdline window: should never be right-left. */
073263
  # ifdef FEAT_FOLDING
073263
! 	n = wp->w_p_fdc;
073263
  
073263
  	if (n > 0)
073263
  	{
073263
--- 2239,2254 ----
073263
  #else
073263
  # define FDC_OFF 0
073263
  #endif
073263
+ #ifdef FEAT_FOLDING
073263
+     int		fdc = compute_foldcolumn(wp, 0);
073263
+ #endif
073263
  
073263
  #ifdef FEAT_RIGHTLEFT
073263
      if (wp->w_p_rl)
073263
      {
073263
  	/* No check for cmdline window: should never be right-left. */
073263
  # ifdef FEAT_FOLDING
073263
! 	n = fdc;
073263
  
073263
  	if (n > 0)
073263
  	{
073263
***************
073263
*** 2293,2301 ****
073263
  	}
073263
  #endif
073263
  #ifdef FEAT_FOLDING
073263
! 	if (wp->w_p_fdc > 0)
073263
  	{
073263
! 	    int	    nn = n + wp->w_p_fdc;
073263
  
073263
  	    /* draw the fold column at the left */
073263
  	    if (nn > W_WIDTH(wp))
073263
--- 2297,2305 ----
073263
  	}
073263
  #endif
073263
  #ifdef FEAT_FOLDING
073263
! 	if (fdc > 0)
073263
  	{
073263
! 	    int	    nn = n + fdc;
073263
  
073263
  	    /* draw the fold column at the left */
073263
  	    if (nn > W_WIDTH(wp))
073263
***************
073263
*** 2346,2351 ****
073263
--- 2350,2373 ----
073263
  
073263
  #ifdef FEAT_FOLDING
073263
  /*
073263
+  * Compute the width of the foldcolumn.  Based on 'foldcolumn' and how much
073263
+  * space is available for window "wp", minus "col".
073263
+  */
073263
+     static int
073263
+ compute_foldcolumn(wp, col)
073263
+     win_T *wp;
073263
+     int   col;
073263
+ {
073263
+     int fdc = wp->w_p_fdc;
073263
+     int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw;
073263
+     int wwidth = W_WIDTH(wp);
073263
+ 
073263
+     if (fdc > wwidth - (col + wmw))
073263
+ 	fdc = wwidth - (col + wmw);
073263
+     return fdc;
073263
+ }
073263
+ 
073263
+ /*
073263
   * Display one folded line.
073263
   */
073263
      static void
073263
***************
073263
*** 2396,2405 ****
073263
  
073263
      /*
073263
       * 2. Add the 'foldcolumn'
073263
       */
073263
!     fdc = wp->w_p_fdc;
073263
!     if (fdc > W_WIDTH(wp) - col)
073263
! 	fdc = W_WIDTH(wp) - col;
073263
      if (fdc > 0)
073263
      {
073263
  	fill_foldcolumn(buf, wp, TRUE, lnum);
073263
--- 2418,2426 ----
073263
  
073263
      /*
073263
       * 2. Add the 'foldcolumn'
073263
+      *    Reduce the width when there is not enough space.
073263
       */
073263
!     fdc = compute_foldcolumn(wp, col);
073263
      if (fdc > 0)
073263
      {
073263
  	fill_foldcolumn(buf, wp, TRUE, lnum);
073263
***************
073263
*** 2787,2809 ****
073263
      int		level;
073263
      int		first_level;
073263
      int		empty;
073263
  
073263
      /* Init to all spaces. */
073263
!     copy_spaces(p, (size_t)wp->w_p_fdc);
073263
  
073263
      level = win_foldinfo.fi_level;
073263
      if (level > 0)
073263
      {
073263
  	/* If there is only one column put more info in it. */
073263
! 	empty = (wp->w_p_fdc == 1) ? 0 : 1;
073263
  
073263
  	/* If the column is too narrow, we start at the lowest level that
073263
  	 * fits and use numbers to indicated the depth. */
073263
! 	first_level = level - wp->w_p_fdc - closed + 1 + empty;
073263
  	if (first_level < 1)
073263
  	    first_level = 1;
073263
  
073263
! 	for (i = 0; i + empty < wp->w_p_fdc; ++i)
073263
  	{
073263
  	    if (win_foldinfo.fi_lnum == lnum
073263
  			      && first_level + i >= win_foldinfo.fi_low_level)
073263
--- 2808,2831 ----
073263
      int		level;
073263
      int		first_level;
073263
      int		empty;
073263
+     int		fdc = compute_foldcolumn(wp, 0);
073263
  
073263
      /* Init to all spaces. */
073263
!     copy_spaces(p, (size_t)fdc);
073263
  
073263
      level = win_foldinfo.fi_level;
073263
      if (level > 0)
073263
      {
073263
  	/* If there is only one column put more info in it. */
073263
! 	empty = (fdc == 1) ? 0 : 1;
073263
  
073263
  	/* If the column is too narrow, we start at the lowest level that
073263
  	 * fits and use numbers to indicated the depth. */
073263
! 	first_level = level - fdc - closed + 1 + empty;
073263
  	if (first_level < 1)
073263
  	    first_level = 1;
073263
  
073263
! 	for (i = 0; i + empty < fdc; ++i)
073263
  	{
073263
  	    if (win_foldinfo.fi_lnum == lnum
073263
  			      && first_level + i >= win_foldinfo.fi_low_level)
073263
***************
073263
*** 2819,2825 ****
073263
  	}
073263
      }
073263
      if (closed)
073263
! 	p[i >= wp->w_p_fdc ? i - 1 : i] = '+';
073263
  }
073263
  #endif /* FEAT_FOLDING */
073263
  
073263
--- 2841,2847 ----
073263
  	}
073263
      }
073263
      if (closed)
073263
! 	p[i >= fdc ? i - 1 : i] = '+';
073263
  }
073263
  #endif /* FEAT_FOLDING */
073263
  
073263
***************
073263
*** 3556,3567 ****
073263
  #ifdef FEAT_FOLDING
073263
  	    if (draw_state == WL_FOLD - 1 && n_extra == 0)
073263
  	    {
073263
  		draw_state = WL_FOLD;
073263
! 		if (wp->w_p_fdc > 0)
073263
  		{
073263
  		    /* Draw the 'foldcolumn'. */
073263
  		    fill_foldcolumn(extra, wp, FALSE, lnum);
073263
! 		    n_extra = wp->w_p_fdc;
073263
  		    p_extra = extra;
073263
  		    p_extra[n_extra] = NUL;
073263
  		    c_extra = NUL;
073263
--- 3578,3591 ----
073263
  #ifdef FEAT_FOLDING
073263
  	    if (draw_state == WL_FOLD - 1 && n_extra == 0)
073263
  	    {
073263
+ 		int fdc = compute_foldcolumn(wp, 0);
073263
+ 
073263
  		draw_state = WL_FOLD;
073263
! 		if (fdc > 0)
073263
  		{
073263
  		    /* Draw the 'foldcolumn'. */
073263
  		    fill_foldcolumn(extra, wp, FALSE, lnum);
073263
! 		    n_extra = fdc;
073263
  		    p_extra = extra;
073263
  		    p_extra[n_extra] = NUL;
073263
  		    c_extra = NUL;
073263
*** ../vim-7.4.602/src/version.c	2015-01-27 15:58:37.202395482 +0100
073263
--- src/version.c	2015-01-27 16:14:45.703878550 +0100
073263
***************
073263
*** 743,744 ****
073263
--- 743,746 ----
073263
  {   /* Add new patch number below this line */
073263
+ /**/
073263
+     603,
073263
  /**/
073263
073263
-- 
073263
hundred-and-one symptoms of being an internet addict:
073263
129. You cancel your newspaper subscription.
073263
073263
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
073263
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
073263
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
073263
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///