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