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