4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
10 NOTE: some mail and patch programs may have a problem with the non-ASCII
11 characters in this patch. You can fetch the patch from
12 ftp://ftp.vim.org/pub/vim/patches/7.2/7.2.301 and/or fetch the updated
13 files from CVS. http://www.vim.org/cvs.php
17 Problem: Formatting is wrong when 'tw' is set to a small value.
18 Solution: Fix it and add tests. Also fix behavior of "1" in 'fo'. (Yukihiro
20 Files: src/edit.c, src/testdir/Makefile, src/testdir/test68.in,
21 src/testdir/test68.ok, src/testdir/test69.in,
25 *** ../vim-7.2.300/src/edit.c 2009-11-11 13:22:32.000000000 +0100
26 --- src/edit.c 2009-11-17 15:34:47.000000000 +0100
29 static void ins_ctrl_v __ARGS((void));
30 static void undisplay_dollar __ARGS((void));
31 static void insert_special __ARGS((int, int, int));
32 ! static void internal_format __ARGS((int textwidth, int second_indent, int flags, int format_only));
33 static void check_auto_format __ARGS((int));
34 static void redo_literal __ARGS((int c));
35 static void start_arrow __ARGS((pos_T *end_insert_pos));
37 static void ins_ctrl_v __ARGS((void));
38 static void undisplay_dollar __ARGS((void));
39 static void insert_special __ARGS((int, int, int));
40 ! static void internal_format __ARGS((int textwidth, int second_indent, int flags, int format_only, int c));
41 static void check_auto_format __ARGS((int));
42 static void redo_literal __ARGS((int c));
43 static void start_arrow __ARGS((pos_T *end_insert_pos));
47 int actual_len; /* Take multi-byte characters */
48 int actual_compl_length; /* into account. */
49 ! int *wca; /* Wide character array. */
50 int has_lower = FALSE;
51 int was_letter = FALSE;
55 int actual_len; /* Take multi-byte characters */
56 int actual_compl_length; /* into account. */
57 ! int *wca; /* Wide character array. */
58 int has_lower = FALSE;
59 int was_letter = FALSE;
66 ! internal_format(textwidth, second_indent, flags, c == NUL);
69 if (c == NUL) /* only formatting was wanted */
74 ! internal_format(textwidth, second_indent, flags, c == NUL, c);
77 if (c == NUL) /* only formatting was wanted */
80 * Format text at the current insert position.
83 ! internal_format(textwidth, second_indent, flags, format_only)
92 * Format text at the current insert position.
95 ! internal_format(textwidth, second_indent, flags, format_only, c)
100 + int c; /* character to be inserted (can be NUL) */
106 * When 'ai' is off we don't want a space under the cursor to be
107 * deleted. Replace it with an 'x' temporarily.
109 ! if (!curbuf->b_p_ai)
114 * When 'ai' is off we don't want a space under the cursor to be
115 * deleted. Replace it with an 'x' temporarily.
117 ! if (!curbuf->b_p_ai
118 ! #ifdef FEAT_VREPLACE
119 ! && !(State & VREPLACE_FLAG)
127 char_u *saved_text = NULL;
131 ! virtcol = get_nolist_virtcol();
132 ! if (virtcol < (colnr_T)textwidth)
137 char_u *saved_text = NULL;
142 ! virtcol = get_nolist_virtcol()
143 ! + char2cells(c != NUL ? c : gchar_cursor());
144 ! if (virtcol <= (colnr_T)textwidth)
150 coladvance((colnr_T)textwidth);
151 wantcol = curwin->w_cursor.col;
153 ! curwin->w_cursor.col = startcol - 1;
155 ! /* Correct cursor for multi-byte character. */
157 ! mb_adjust_cursor();
163 coladvance((colnr_T)textwidth);
164 wantcol = curwin->w_cursor.col;
166 ! curwin->w_cursor.col = startcol;
172 || curwin->w_cursor.lnum != Insstart.lnum
173 || curwin->w_cursor.col >= Insstart.col)
175 ! cc = gchar_cursor();
178 /* remember position of blank just before text */
179 ! end_foundcol = curwin->w_cursor.col;
181 /* find start of sequence of blanks */
182 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
184 || curwin->w_cursor.lnum != Insstart.lnum
185 || curwin->w_cursor.col >= Insstart.col)
187 ! if (curwin->w_cursor.col == startcol && c != NUL)
190 ! cc = gchar_cursor();
193 /* remember position of blank just before text */
194 ! end_col = curwin->w_cursor.col;
196 /* find start of sequence of blanks */
197 while (curwin->w_cursor.col > 0 && WHITECHAR(cc))
200 /* do not break after one-letter words */
201 if (curwin->w_cursor.col == 0)
202 break; /* one-letter word at begin */
204 col = curwin->w_cursor.col;
208 /* do not break after one-letter words */
209 if (curwin->w_cursor.col == 0)
210 break; /* one-letter word at begin */
211 ! #ifdef FEAT_COMMENTS
212 ! /* do not break "#a b" when 'tw' is 2 */
213 ! if (curwin->w_cursor.col <= leader_len)
216 col = curwin->w_cursor.col;
221 continue; /* one-letter, continue */
222 curwin->w_cursor.col = col;
226 ! foundcol = curwin->w_cursor.col
227 ! + (*mb_ptr2len)(ml_get_cursor());
230 ! foundcol = curwin->w_cursor.col + 1;
231 ! if (curwin->w_cursor.col < (colnr_T)wantcol)
235 ! else if (cc >= 0x100 && fo_multibyte
236 ! && curwin->w_cursor.col <= (colnr_T)wantcol)
238 /* Break after or before a multi-byte character. */
239 foundcol = curwin->w_cursor.col;
240 - if (curwin->w_cursor.col < (colnr_T)wantcol)
241 - foundcol += (*mb_char2len)(cc);
242 end_foundcol = foundcol;
246 if (curwin->w_cursor.col == 0)
248 continue; /* one-letter, continue */
249 curwin->w_cursor.col = col;
254 ! end_foundcol = end_col + 1;
255 ! foundcol = curwin->w_cursor.col;
256 ! if (curwin->w_cursor.col <= (colnr_T)wantcol)
260 ! else if (cc >= 0x100 && fo_multibyte)
262 /* Break after or before a multi-byte character. */
263 + if (curwin->w_cursor.col != startcol)
265 + #ifdef FEAT_COMMENTS
266 + /* Don't break until after the comment leader */
267 + if (curwin->w_cursor.col < leader_len)
270 + col = curwin->w_cursor.col;
272 + /* Don't change end_foundcol if already set. */
273 + if (foundcol != curwin->w_cursor.col)
275 + foundcol = curwin->w_cursor.col;
276 + end_foundcol = foundcol;
277 + if (curwin->w_cursor.col <= (colnr_T)wantcol)
280 + curwin->w_cursor.col = col;
283 + if (curwin->w_cursor.col == 0)
286 + col = curwin->w_cursor.col;
289 + cc = gchar_cursor();
292 + continue; /* break with space */
293 + #ifdef FEAT_COMMENTS
294 + /* Don't break until after the comment leader */
295 + if (curwin->w_cursor.col < leader_len)
299 + curwin->w_cursor.col = col;
301 foundcol = curwin->w_cursor.col;
302 end_foundcol = foundcol;
303 ! if (curwin->w_cursor.col <= (colnr_T)wantcol)
307 if (curwin->w_cursor.col == 0)
310 orig_col = startcol; /* Will start backspacing from here */
313 ! replace_offset = startcol - end_foundcol - 1;
316 * adjust startcol for spaces that will be deleted and
317 * characters that will remain on top line
319 curwin->w_cursor.col = foundcol;
320 ! while (cc = gchar_cursor(), WHITECHAR(cc))
322 startcol -= curwin->w_cursor.col;
325 orig_col = startcol; /* Will start backspacing from here */
328 ! replace_offset = startcol - end_foundcol;
331 * adjust startcol for spaces that will be deleted and
332 * characters that will remain on top line
334 curwin->w_cursor.col = foundcol;
335 ! while ((cc = gchar_cursor(), WHITECHAR(cc))
336 ! && (!fo_white_par || curwin->w_cursor.col < startcol))
338 startcol -= curwin->w_cursor.col;
342 if (mode == BACKSPACE_LINE
348 #ifdef FEAT_RIGHTLEFT
350 if (mode == BACKSPACE_LINE
356 #ifdef FEAT_RIGHTLEFT
357 *** ../vim-7.2.300/src/testdir/Makefile 2009-11-17 17:36:13.000000000 +0100
358 --- src/testdir/Makefile 2009-11-17 15:11:26.000000000 +0100
361 test48.out test49.out test51.out test52.out test53.out \
362 test54.out test55.out test56.out test57.out test58.out \
363 test59.out test60.out test61.out test62.out test63.out \
364 ! test64.out test65.out test66.out test67.out
366 SCRIPTS_GUI = test16.out
369 test48.out test49.out test51.out test52.out test53.out \
370 test54.out test55.out test56.out test57.out test58.out \
371 test59.out test60.out test61.out test62.out test63.out \
372 ! test64.out test65.out test66.out test67.out test68.out \
375 SCRIPTS_GUI = test16.out
377 *** ../vim-7.2.300/src/testdir/test68.in 2009-11-17 17:39:36.000000000 +0100
378 --- src/testdir/test68.in 2009-11-17 15:39:09.000000000 +0100
382 + Test for text formatting.
389 + :set noai tw=2 fo=t
423 + :set tw=2 fo=tcq1 comments=:#
435 + :g/^STARTTEST/.,/^ENDTEST/d
436 + :1;/^Results/,$wq! test.out
438 *** ../vim-7.2.300/src/testdir/test68.ok 2009-11-17 17:39:36.000000000 +0100
439 --- src/testdir/test68.ok 2009-11-17 15:11:26.000000000 +0100
478 *** ../vim-7.2.300/src/testdir/test69.in 2009-11-17 17:39:36.000000000 +0100
479 --- src/testdir/test69.in 2009-11-17 15:11:26.000000000 +0100
483 + Test for multi-byte text formatting.
487 + :set encoding=utf-8
508 + gqgqjgqgqjgqgqjgqgqjgqgqo
527 + gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo
568 + :set noai tw=2 fo=tm
581 + :set tw=2 fo=cqm comments=n:X
582 + gqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqjgqgqo
619 + :g/^STARTTEST/.,/^ENDTEST/d
620 + :1;/^Results/,$wq! test.out
622 *** ../vim-7.2.300/src/testdir/test69.ok 2009-11-17 17:39:36.000000000 +0100
623 --- src/testdir/test69.ok 2009-11-17 15:11:26.000000000 +0100
769 *** ../vim-7.2.300/src/version.c 2009-11-17 17:37:34.000000000 +0100
770 --- src/version.c 2009-11-17 17:26:35.000000000 +0100
774 { /* Add new patch number below this line */