• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisión60d21d224d251c448ef76b1b9df087497c06adf4 (tree)
Tiempo2007-07-24 22:26:15
Autorvimboss
Commitervimboss

Log Message

updated for version 7.1-038

Cambiar Resumen

Diferencia incremental

diff -r 454d71a43417 -r 60d21d224d25 src/misc1.c
--- a/src/misc1.c Tue Jul 24 12:58:01 2007 +0000
+++ b/src/misc1.c Tue Jul 24 13:26:15 2007 +0000
@@ -90,7 +90,7 @@
9090 */
9191 int
9292 set_indent(size, flags)
93- int size;
93+ int size; /* measured in spaces */
9494 int flags;
9595 {
9696 char_u *p;
@@ -98,12 +98,14 @@
9898 char_u *oldline;
9999 char_u *s;
100100 int todo;
101- int ind_len;
101+ int ind_len; /* measured in characters */
102102 int line_len;
103103 int doit = FALSE;
104- int ind_done;
104+ int ind_done = 0; /* measured in spaces */
105105 int tab_pad;
106106 int retval = FALSE;
107+ int orig_char_len = 0; /* number of initial whitespace chars when
108+ 'et' and 'pi' are both set */
107109
108110 /*
109111 * First check if there is anything to do and compute the number of
@@ -116,8 +118,10 @@
116118 /* Calculate the buffer size for the new indent, and check to see if it
117119 * isn't already set */
118120
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))
121125 {
122126 /* If 'preserveindent' is set then reuse as much as possible of
123127 * the existing indent structure for the new indent */
@@ -148,9 +152,14 @@
148152 ++p;
149153 }
150154
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+
151160 /* Fill to next tabstop with a tab, if possible */
152161 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)
154163 {
155164 doit = TRUE;
156165 todo -= tab_pad;
@@ -193,13 +202,38 @@
193202 else
194203 p = skipwhite(p);
195204 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+ }
199235
200236 /* Put the characters in the new line. */
201- s = newline;
202- todo = size;
203237 /* if 'expandtab' isn't set: use TABs */
204238 if (!curbuf->b_p_et)
205239 {
@@ -1320,8 +1354,8 @@
13201354 newindent += (int)curbuf->b_p_sw;
13211355 }
13221356 #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)
13251359 {
13261360 (void)copy_indent(newindent, saved_line);
13271361
diff -r 454d71a43417 -r 60d21d224d25 src/version.c
--- a/src/version.c Tue Jul 24 12:58:01 2007 +0000
+++ b/src/version.c Tue Jul 24 13:26:15 2007 +0000
@@ -667,6 +667,8 @@
667667 static int included_patches[] =
668668 { /* Add new patch number below this line */
669669 /**/
670+ 38,
671+/**/
670672 37,
671673 /**/
672674 36,
Show on old repository browser