Mirror of the Vim source from https://github.com/vim/vim
Revisión | 60d21d224d251c448ef76b1b9df087497c06adf4 (tree) |
---|---|
Tiempo | 2007-07-24 22:26:15 |
Autor | vimboss |
Commiter | vimboss |
updated for version 7.1-038
@@ -90,7 +90,7 @@ | ||
90 | 90 | */ |
91 | 91 | int |
92 | 92 | set_indent(size, flags) |
93 | - int size; | |
93 | + int size; /* measured in spaces */ | |
94 | 94 | int flags; |
95 | 95 | { |
96 | 96 | char_u *p; |
@@ -98,12 +98,14 @@ | ||
98 | 98 | char_u *oldline; |
99 | 99 | char_u *s; |
100 | 100 | int todo; |
101 | - int ind_len; | |
101 | + int ind_len; /* measured in characters */ | |
102 | 102 | int line_len; |
103 | 103 | int doit = FALSE; |
104 | - int ind_done; | |
104 | + int ind_done = 0; /* measured in spaces */ | |
105 | 105 | int tab_pad; |
106 | 106 | int retval = FALSE; |
107 | + int orig_char_len = 0; /* number of initial whitespace chars when | |
108 | + 'et' and 'pi' are both set */ | |
107 | 109 | |
108 | 110 | /* |
109 | 111 | * First check if there is anything to do and compute the number of |
@@ -116,8 +118,10 @@ | ||
116 | 118 | /* Calculate the buffer size for the new indent, and check to see if it |
117 | 119 | * isn't already set */ |
118 | 120 | |
119 | - /* if 'expandtab' isn't set: use TABs */ | |
120 | - if (!curbuf->b_p_et) | |
121 | + /* if 'expandtab' isn't set: use TABs; if both 'expandtab' and | |
122 | + * 'preserveindent' are set count the number of characters at the | |
123 | + * beginning of the line to be copied */ | |
124 | + if (!curbuf->b_p_et || (!(flags & SIN_INSERT) && curbuf->b_p_pi)) | |
121 | 125 | { |
122 | 126 | /* If 'preserveindent' is set then reuse as much as possible of |
123 | 127 | * the existing indent structure for the new indent */ |
@@ -148,9 +152,14 @@ | ||
148 | 152 | ++p; |
149 | 153 | } |
150 | 154 | |
155 | + /* Set initial number of whitespace chars to copy if we are | |
156 | + * preserving indent but expandtab is set */ | |
157 | + if (curbuf->b_p_et) | |
158 | + orig_char_len = ind_len; | |
159 | + | |
151 | 160 | /* Fill to next tabstop with a tab, if possible */ |
152 | 161 | tab_pad = (int)curbuf->b_p_ts - (ind_done % (int)curbuf->b_p_ts); |
153 | - if (todo >= tab_pad) | |
162 | + if (todo >= tab_pad && orig_char_len == 0) | |
154 | 163 | { |
155 | 164 | doit = TRUE; |
156 | 165 | todo -= tab_pad; |
@@ -193,13 +202,38 @@ | ||
193 | 202 | else |
194 | 203 | p = skipwhite(p); |
195 | 204 | line_len = (int)STRLEN(p) + 1; |
196 | - newline = alloc(ind_len + line_len); | |
197 | - if (newline == NULL) | |
198 | - return FALSE; | |
205 | + | |
206 | + /* If 'preserveindent' and 'expandtab' are both set keep the original | |
207 | + * characters and allocate accordingly. We will fill the rest with spaces | |
208 | + * after the if (!curbuf->b_p_et) below. */ | |
209 | + if (orig_char_len != 0) | |
210 | + { | |
211 | + newline = alloc(orig_char_len + size - ind_done + line_len); | |
212 | + if (newline == NULL) | |
213 | + return FALSE; | |
214 | + p = oldline; | |
215 | + s = newline; | |
216 | + while (orig_char_len > 0) | |
217 | + { | |
218 | + *s++ = *p++; | |
219 | + orig_char_len--; | |
220 | + } | |
221 | + /* Skip over any additional white space (useful when newindent is less | |
222 | + * than old) */ | |
223 | + while (vim_iswhite(*p)) | |
224 | + (void)*p++; | |
225 | + todo = size-ind_done; | |
226 | + } | |
227 | + else | |
228 | + { | |
229 | + todo = size; | |
230 | + newline = alloc(ind_len + line_len); | |
231 | + if (newline == NULL) | |
232 | + return FALSE; | |
233 | + s = newline; | |
234 | + } | |
199 | 235 | |
200 | 236 | /* Put the characters in the new line. */ |
201 | - s = newline; | |
202 | - todo = size; | |
203 | 237 | /* if 'expandtab' isn't set: use TABs */ |
204 | 238 | if (!curbuf->b_p_et) |
205 | 239 | { |
@@ -1320,8 +1354,8 @@ | ||
1320 | 1354 | newindent += (int)curbuf->b_p_sw; |
1321 | 1355 | } |
1322 | 1356 | #endif |
1323 | - /* Copy the indent only if expand tab is disabled */ | |
1324 | - if (curbuf->b_p_ci && !curbuf->b_p_et) | |
1357 | + /* Copy the indent */ | |
1358 | + if (curbuf->b_p_ci) | |
1325 | 1359 | { |
1326 | 1360 | (void)copy_indent(newindent, saved_line); |
1327 | 1361 |
@@ -667,6 +667,8 @@ | ||
667 | 667 | static int included_patches[] = |
668 | 668 | { /* Add new patch number below this line */ |
669 | 669 | /**/ |
670 | + 38, | |
671 | +/**/ | |
670 | 672 | 37, |
671 | 673 | /**/ |
672 | 674 | 36, |