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