1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: Formatting of lists inside comments is not right yet.
12 Solution: Use another solution and add a test. (Tor Perkins)
13 Files: src/edit.c, src/misc1.c, src/testdir/test68.in,
17 *** ../vim-7.3.575/src/edit.c 2012-06-20 22:55:56.000000000 +0200
18 --- src/edit.c 2012-06-29 14:10:36.000000000 +0200
21 if (!(flags & INSCHAR_COM_LIST))
24 ! * This section is for numeric lists w/o comments. If comment
25 ! * indents are needed with numeric lists (formatoptions=nq),
26 ! * then the INSCHAR_COM_LIST flag will cause the corresponding
27 ! * OPENLINE_COM_LIST flag to be passed through to open_line()
28 ! * (as seen above)...
30 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
31 ! second_indent = get_number_indent(curwin->w_cursor.lnum -1);
32 if (second_indent >= 0)
36 if (!(flags & INSCHAR_COM_LIST))
39 ! * This section is for auto-wrap of numeric lists. When not
40 ! * in insert mode (i.e. format_lines()), the INSCHAR_COM_LIST
41 ! * flag will be set and open_line() will handle it (as seen
42 ! * above). The code here (and in get_number_indent()) will
43 ! * recognize comments if needed...
45 if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
47 ! get_number_indent(curwin->w_cursor.lnum - 1);
48 if (second_indent >= 0)
57 + #ifdef FEAT_COMMENTS
58 + if (leader_len > 0 && second_indent - leader_len > 0)
61 + int padding = second_indent - leader_len;
63 + /* We started at the first_line of a numbered list
64 + * that has a comment. the open_line() function has
65 + * inserted the proper comment leader and positioned
66 + * the cursor at the end of the split line. Now we
67 + * add the additional whitespace needed after the
68 + * comment leader for the numbered list. */
69 + for (i = 0; i < padding; i++)
71 + ins_str((char_u *)" ");
72 + changed_bytes(curwin->w_cursor.lnum, leader_len);
78 (void)set_indent(second_indent, SIN_CHANGED);
79 + #ifdef FEAT_COMMENTS
85 *** ../vim-7.3.575/src/misc1.c 2012-06-20 17:56:06.000000000 +0200
86 --- src/misc1.c 2012-06-29 14:10:12.000000000 +0200
92 if (lnum > curbuf->b_ml.ml_line_count)
97 ! if (has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER))
99 ! regmatch_T regmatch;
100 ! int lead_len; /* length of comment leader */
102 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
103 - regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
104 - if (regmatch.regprog != NULL)
106 - regmatch.rm_ic = FALSE;
108 - /* vim_regexec() expects a pointer to a line. This lets us
109 - * start matching for the flp beyond any comment leader... */
110 - if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0))
113 - pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
114 - #ifdef FEAT_VIRTUALEDIT
119 ! vim_free(regmatch.regprog);
124 ! * What follows is the orig code that is not "comment aware"...
126 ! * I'm not sure if regmmatch_T (multi-match) is needed in this case.
127 ! * It may be true that this section would work properly using the
128 ! * regmatch_T code above, in which case, these two separate sections
129 ! * should be consolidated w/ FEAT_COMMENTS making lead_len > 0...
132 ! regmmatch_T regmatch;
134 ! regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
136 ! if (regmatch.regprog != NULL)
138 ! regmatch.rmm_ic = FALSE;
139 ! regmatch.rmm_maxcol = 0;
140 ! if (vim_regexec_multi(®match, curwin, curbuf,
141 ! lnum, (colnr_T)0, NULL))
143 ! pos.lnum = regmatch.endpos[0].lnum + lnum;
144 ! pos.col = regmatch.endpos[0].col;
145 #ifdef FEAT_VIRTUALEDIT
149 - vim_free(regmatch.regprog);
151 - #ifdef FEAT_COMMENTS
155 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
161 + regmatch_T regmatch;
162 + int lead_len = 0; /* length of comment leader */
164 if (lnum > curbuf->b_ml.ml_line_count)
169 ! /* In format_lines() (i.e. not insert mode), fo+=q is needed too... */
170 ! if ((State & INSERT) || has_format_option(FO_Q_COMS))
171 lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
173 ! regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
174 ! if (regmatch.regprog != NULL)
176 ! regmatch.rm_ic = FALSE;
178 ! /* vim_regexec() expects a pointer to a line. This lets us
179 ! * start matching for the flp beyond any comment leader... */
180 ! if (vim_regexec(®match, ml_get(lnum) + lead_len, (colnr_T)0))
183 ! pos.col = (colnr_T)(*regmatch.endp - ml_get(lnum));
184 #ifdef FEAT_VIRTUALEDIT
189 ! vim_free(regmatch.regprog);
191 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
193 *** ../vim-7.3.575/src/testdir/test68.in 2012-06-13 17:28:51.000000000 +0200
194 --- src/testdir/test68.in 2012-06-29 14:27:27.000000000 +0200
201 + :set tw=5 fo=tcn comments=:#
212 :set tw=5 fo=qn comments=:#
222 + :setl tw=12 fo=tqnc comments=:#
229 :g/^STARTTEST/.,/^ENDTEST/d
230 :1;/^Results/,$wq! test.out
232 *** ../vim-7.3.575/src/version.c 2012-06-29 13:56:01.000000000 +0200
233 --- src/version.c 2012-06-29 15:03:10.000000000 +0200
237 { /* Add new patch number below this line */
243 Proof techniques #2: Proof by Oddity.
244 SAMPLE: To prove that horses have an infinite number of legs.
245 (1) Horses have an even number of legs.
246 (2) They have two legs in back and fore legs in front.
247 (3) This makes a total of six legs, which certainly is an odd number of
249 (4) But the only number that is both odd and even is infinity.
250 (5) Therefore, horses must have an infinite number of legs.
252 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
253 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
254 \\\ an exciting new programming language -- http://www.Zimbu.org ///
255 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///