94a9762
To: vim-dev@vim.org
94a9762
Subject: patch 7.1.038
94a9762
Fcc: outbox
94a9762
From: Bram Moolenaar <Bram@moolenaar.net>
94a9762
Mime-Version: 1.0
94a9762
Content-Type: text/plain; charset=ISO-8859-1
94a9762
Content-Transfer-Encoding: 8bit
94a9762
------------
94a9762
94a9762
Patch 7.1.038
94a9762
Problem:    When 'expandtab' is set then a Tab copied for 'copyindent' is
94a9762
	    expanded to spaces, even when 'preserveindent' is set. (Alexei
94a9762
	    Alexandrov)
94a9762
Solution:   Remove the check for 'expandtab'.  Also fix that ">>" doesn't obey
94a9762
	    'preserveindent'. (Chris Lubinski)
94a9762
Files:	    src/misc1.c
94a9762
94a9762
94a9762
*** ../vim-7.1.037/src/misc1.c	Thu May 10 21:03:33 2007
94a9762
--- src/misc1.c	Tue Jul 24 15:24:50 2007
94a9762
***************
94a9762
*** 90,96 ****
94a9762
   */
94a9762
      int
94a9762
  set_indent(size, flags)
94a9762
!     int		size;
94a9762
      int		flags;
94a9762
  {
94a9762
      char_u	*p;
94a9762
--- 90,96 ----
94a9762
   */
94a9762
      int
94a9762
  set_indent(size, flags)
94a9762
!     int		size;		    /* measured in spaces */
94a9762
      int		flags;
94a9762
  {
94a9762
      char_u	*p;
94a9762
***************
94a9762
*** 98,109 ****
94a9762
      char_u	*oldline;
94a9762
      char_u	*s;
94a9762
      int		todo;
94a9762
!     int		ind_len;
94a9762
      int		line_len;
94a9762
      int		doit = FALSE;
94a9762
!     int		ind_done;
94a9762
      int		tab_pad;
94a9762
      int		retval = FALSE;
94a9762
  
94a9762
      /*
94a9762
       * First check if there is anything to do and compute the number of
94a9762
--- 98,111 ----
94a9762
      char_u	*oldline;
94a9762
      char_u	*s;
94a9762
      int		todo;
94a9762
!     int		ind_len;	    /* measured in characters */
94a9762
      int		line_len;
94a9762
      int		doit = FALSE;
94a9762
!     int		ind_done = 0;	    /* measured in spaces */
94a9762
      int		tab_pad;
94a9762
      int		retval = FALSE;
94a9762
+     int		orig_char_len = 0;  /* number of initial whitespace chars when
94a9762
+ 				       'et' and 'pi' are both set */
94a9762
  
94a9762
      /*
94a9762
       * First check if there is anything to do and compute the number of
94a9762
***************
94a9762
*** 116,123 ****
94a9762
      /* Calculate the buffer size for the new indent, and check to see if it
94a9762
       * isn't already set */
94a9762
  
94a9762
!     /* if 'expandtab' isn't set: use TABs */
94a9762
!     if (!curbuf->b_p_et)
94a9762
      {
94a9762
  	/* If 'preserveindent' is set then reuse as much as possible of
94a9762
  	 * the existing indent structure for the new indent */
94a9762
--- 118,127 ----
94a9762
      /* Calculate the buffer size for the new indent, and check to see if it
94a9762
       * isn't already set */
94a9762
  
94a9762
!     /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and
94a9762
!      * 'preserveindent' are set count the number of characters at the
94a9762
!      * beginning of the line to be copied */
94a9762
!     if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi))
94a9762
      {
94a9762
  	/* If 'preserveindent' is set then reuse as much as possible of
94a9762
  	 * the existing indent structure for the new indent */
94a9762
***************
94a9762
*** 148,156 ****
94a9762
  		++p;
94a9762
  	    }
94a9762
  
94a9762
  	    /* Fill to next tabstop with a tab, if possible */
94a9762
  	    tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
94a9762
! 	    if (todo >= tab_pad)
94a9762
  	    {
94a9762
  		doit = TRUE;
94a9762
  		todo -= tab_pad;
94a9762
--- 152,165 ----
94a9762
  		++p;
94a9762
  	    }
94a9762
  
94a9762
+ 	    /* Set initial number of whitespace chars to copy if we are
94a9762
+ 	     * preserving indent but expandtab is set */
94a9762
+ 	    if (curbuf->b_p_et)
94a9762
+ 		orig_char_len = ind_len;
94a9762
+ 
94a9762
  	    /* Fill to next tabstop with a tab, if possible */
94a9762
  	    tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts);
94a9762
! 	    if (todo >= tab_pad && orig_char_len == 0)
94a9762
  	    {
94a9762
  		doit = TRUE;
94a9762
  		todo -= tab_pad;
94a9762
***************
94a9762
*** 193,205 ****
94a9762
      else
94a9762
  	p = skipwhite(p);
94a9762
      line_len = (int)STRLEN(p) + 1;
94a9762
!     newline = alloc(ind_len + line_len);
94a9762
!     if (newline == NULL)
94a9762
! 	return FALSE;
94a9762
  
94a9762
      /* Put the characters in the new line. */
94a9762
-     s = newline;
94a9762
-     todo = size;
94a9762
      /* if 'expandtab' isn't set: use TABs */
94a9762
      if (!curbuf->b_p_et)
94a9762
      {
94a9762
--- 202,239 ----
94a9762
      else
94a9762
  	p = skipwhite(p);
94a9762
      line_len = (int)STRLEN(p) + 1;
94a9762
! 
94a9762
!     /* If 'preserveindent' and 'expandtab' are both set keep the original
94a9762
!      * characters and allocate accordingly.  We will fill the rest with spaces
94a9762
!      * after the if (!curbuf->b_p_et) below. */
94a9762
!     if (orig_char_len != 0)
94a9762
!     {
94a9762
! 	newline = alloc(orig_char_len + size - ind_done + line_len);
94a9762
! 	if (newline == NULL)
94a9762
! 	    return FALSE;
94a9762
! 	p = oldline;
94a9762
! 	s = newline;
94a9762
! 	while (orig_char_len > 0)
94a9762
! 	{
94a9762
! 	    *s++ = *p++;
94a9762
! 	    orig_char_len--;
94a9762
! 	}
94a9762
! 	/* Skip over any additional white space (useful when newindent is less
94a9762
! 	 * than old) */
94a9762
! 	while (vim_iswhite(*p))
94a9762
! 	    (void)*p++;
94a9762
! 	todo = size-ind_done;
94a9762
!     }
94a9762
!     else
94a9762
!     {
94a9762
! 	todo = size;
94a9762
! 	newline = alloc(ind_len + line_len);
94a9762
! 	if (newline == NULL)
94a9762
! 	    return FALSE;
94a9762
! 	s = newline;
94a9762
!     }
94a9762
  
94a9762
      /* Put the characters in the new line. */
94a9762
      /* if 'expandtab' isn't set: use TABs */
94a9762
      if (!curbuf->b_p_et)
94a9762
      {
94a9762
***************
94a9762
*** 1320,1327 ****
94a9762
  	    newindent += (int)curbuf->b_p_sw;
94a9762
  	}
94a9762
  #endif
94a9762
! 	/* Copy the indent only if expand tab is disabled */
94a9762
! 	if (curbuf->b_p_ci && !curbuf->b_p_et)
94a9762
  	{
94a9762
  	    (void)copy_indent(newindent, saved_line);
94a9762
  
94a9762
--- 1354,1361 ----
94a9762
  	    newindent += (int)curbuf->b_p_sw;
94a9762
  	}
94a9762
  #endif
94a9762
! 	/* Copy the indent */
94a9762
! 	if (curbuf->b_p_ci)
94a9762
  	{
94a9762
  	    (void)copy_indent(newindent, saved_line);
94a9762
  
94a9762
*** ../vim-7.1.037/src/version.c	Tue Jul 24 14:57:16 2007
94a9762
--- src/version.c	Tue Jul 24 15:22:44 2007
94a9762
***************
94a9762
*** 668,669 ****
94a9762
--- 668,671 ----
94a9762
  {   /* Add new patch number below this line */
94a9762
+ /**/
94a9762
+     38,
94a9762
  /**/
94a9762
94a9762
-- 
94a9762
Time is an illusion.  Lunchtime doubly so.
94a9762
		-- Ford Prefect, in Douglas Adams'
94a9762
		   "The Hitchhiker's Guide to the Galaxy"
94a9762
94a9762
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
94a9762
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
94a9762
\\\        download, build and distribute -- http://www.A-A-P.org        ///
94a9762
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///