]> git.pld-linux.org Git - packages/vim.git/blame - 7.3.552
- up to 7.3.600
[packages/vim.git] / 7.3.552
CommitLineData
8bb52fd3
ER
1To: vim_dev@googlegroups.com
2Subject: Patch 7.3.552
3Fcc: outbox
4From: Bram Moolenaar <Bram@moolenaar.net>
5Mime-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8------------
9
10Patch 7.3.552
11Problem: Formatting inside comments does not use the "2" flag in
12 'formatoptions'.
13Solution: Support the "2" flag. (Tor Perkins)
14Files: src/vim.h, src/ops.c, src/edit.c, src/misc1.c,
15 src/testdir/test68.in, src/testdir/test68.ok
16
17
18*** ../vim-7.3.551/src/vim.h 2012-06-06 18:03:01.000000000 +0200
19--- src/vim.h 2012-06-13 16:07:27.000000000 +0200
20***************
21*** 1072,1083 ****
22--- 1072,1085 ----
23 #define INSCHAR_DO_COM 2 /* format comments */
24 #define INSCHAR_CTRLV 4 /* char typed just after CTRL-V */
25 #define INSCHAR_NO_FEX 8 /* don't use 'formatexpr' */
26+ #define INSCHAR_COM_LIST 16 /* format comments with list/2nd line indent */
27
28 /* flags for open_line() */
29 #define OPENLINE_DELSPACES 1 /* delete spaces after cursor */
30 #define OPENLINE_DO_COM 2 /* format comments */
31 #define OPENLINE_KEEPTRAIL 4 /* keep trailing spaces */
32 #define OPENLINE_MARKFIX 8 /* fix mark positions */
33+ #define OPENLINE_COM_LIST 16 /* format comments with list/2nd line indent */
34
35 /*
36 * There are four history tables:
37*** ../vim-7.3.551/src/ops.c 2012-06-13 14:01:36.000000000 +0200
38--- src/ops.c 2012-06-13 16:53:44.000000000 +0200
39***************
40*** 1727,1734 ****
41 * and the delete is within one line. */
42 if ((
43 #ifdef FEAT_CLIPBOARD
44! ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') ||
45! ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') ||
46 #endif
47 oap->regname == 0) && oap->motion_type != MLINE
48 && oap->line_count == 1)
49--- 1727,1734 ----
50 * and the delete is within one line. */
51 if ((
52 #ifdef FEAT_CLIPBOARD
53! ((clip_unnamed & CLIP_UNNAMED) && oap->regname == '*') ||
54! ((clip_unnamed & CLIP_UNNAMED_PLUS) && oap->regname == '+') ||
55 #endif
56 oap->regname == 0) && oap->motion_type != MLINE
57 && oap->line_count == 1)
58***************
59*** 4208,4217 ****
60 * "is_comment".
61 * line - line to be processed,
62 * process - if FALSE, will only check whether the line ends with an unclosed
63! * comment,
64 * include_space - whether to also skip space following the comment leader,
65 * is_comment - will indicate whether the current line ends with an unclosed
66! * comment.
67 */
68 static char_u *
69 skip_comment(line, process, include_space, is_comment)
70--- 4208,4217 ----
71 * "is_comment".
72 * line - line to be processed,
73 * process - if FALSE, will only check whether the line ends with an unclosed
74! * comment,
75 * include_space - whether to also skip space following the comment leader,
76 * is_comment - will indicate whether the current line ends with an unclosed
77! * comment.
78 */
79 static char_u *
80 skip_comment(line, process, include_space, is_comment)
81***************
82*** 4723,4731 ****
83 char_u *leader_flags = NULL; /* flags for leader of current line */
84 char_u *next_leader_flags; /* flags for leader of next line */
85 int do_comments; /* format comments */
86 #endif
87 int advance = TRUE;
88! int second_indent = -1;
89 int do_second_indent;
90 int do_number_indent;
91 int do_trail_white;
92--- 4723,4733 ----
93 char_u *leader_flags = NULL; /* flags for leader of current line */
94 char_u *next_leader_flags; /* flags for leader of next line */
95 int do_comments; /* format comments */
96+ int do_comments_list = 0; /* format comments with 'n' or '2' */
97 #endif
98 int advance = TRUE;
99! int second_indent = -1; /* indent for second line (comment
100! * aware) */
101 int do_second_indent;
102 int do_number_indent;
103 int do_trail_white;
104***************
105*** 4828,4845 ****
106 if (first_par_line
107 && (do_second_indent || do_number_indent)
108 && prev_is_end_par
109! && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count
110 #ifdef FEAT_COMMENTS
111! && leader_len == 0
112! && next_leader_len == 0
113 #endif
114! )
115! {
116! if (do_second_indent
117! && !lineempty(curwin->w_cursor.lnum + 1))
118! second_indent = get_indent_lnum(curwin->w_cursor.lnum + 1);
119 else if (do_number_indent)
120! second_indent = get_number_indent(curwin->w_cursor.lnum);
121 }
122
123 /*
124--- 4830,4875 ----
125 if (first_par_line
126 && (do_second_indent || do_number_indent)
127 && prev_is_end_par
128! && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count)
129! {
130! if (do_second_indent && !lineempty(curwin->w_cursor.lnum + 1))
131! {
132 #ifdef FEAT_COMMENTS
133! if (leader_len == 0 && next_leader_len == 0)
134! {
135! /* no comment found */
136 #endif
137! second_indent =
138! get_indent_lnum(curwin->w_cursor.lnum + 1);
139! #ifdef FEAT_COMMENTS
140! }
141! else
142! {
143! second_indent = next_leader_len;
144! do_comments_list = 1;
145! }
146! #endif
147! }
148 else if (do_number_indent)
149! {
150! #ifdef FEAT_COMMENTS
151! if (leader_len == 0 && next_leader_len == 0)
152! {
153! /* no comment found */
154! #endif
155! second_indent =
156! get_number_indent(curwin->w_cursor.lnum);
157! #ifdef FEAT_COMMENTS
158! }
159! else
160! {
161! /* get_number_indent() is now "comment aware"... */
162! second_indent =
163! get_number_indent(curwin->w_cursor.lnum);
164! do_comments_list = 1;
165! }
166! #endif
167! }
168 }
169
170 /*
171***************
172*** 4878,4883 ****
173--- 4908,4915 ----
174 insertchar(NUL, INSCHAR_FORMAT
175 #ifdef FEAT_COMMENTS
176 + (do_comments ? INSCHAR_DO_COM : 0)
177+ + (do_comments && do_comments_list
178+ ? INSCHAR_COM_LIST : 0)
179 #endif
180 + (avoid_fex ? INSCHAR_NO_FEX : 0), second_indent);
181 State = old_State;
182*** ../vim-7.3.551/src/edit.c 2012-06-06 16:12:54.000000000 +0200
183--- src/edit.c 2012-06-13 16:54:10.000000000 +0200
184***************
185*** 1463,1469 ****
186 * what check_abbr() expects. */
187 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
188 #endif
189! c) && c != Ctrl_RSB))
190 {
191 insert_special(c, FALSE, FALSE);
192 #ifdef FEAT_RIGHTLEFT
193--- 1463,1469 ----
194 * what check_abbr() expects. */
195 (has_mbyte && c >= 0x100) ? (c + ABBR_OFF) :
196 #endif
197! c) && c != Ctrl_RSB))
198 {
199 insert_special(c, FALSE, FALSE);
200 #ifdef FEAT_RIGHTLEFT
201***************
202*** 5769,5774 ****
203--- 5769,5784 ----
204 # define WHITECHAR(cc) vim_iswhite(cc)
205 #endif
206
207+ /*
208+ * "flags": INSCHAR_FORMAT - force formatting
209+ * INSCHAR_CTRLV - char typed just after CTRL-V
210+ * INSCHAR_NO_FEX - don't use 'formatexpr'
211+ *
212+ * NOTE: passes the flags value straight through to internal_format() which,
213+ * beside INSCHAR_FORMAT (above), is also looking for these:
214+ * INSCHAR_DO_COM - format comments
215+ * INSCHAR_COM_LIST - format comments with num list or 2nd line indent
216+ */
217 void
218 insertchar(c, flags, second_indent)
219 int c; /* character to insert or NUL */
220***************
221*** 6011,6016 ****
222--- 6021,6029 ----
223
224 /*
225 * Format text at the current insert position.
226+ *
227+ * If the INSCHAR_COM_LIST flag is present, then the value of second_indent
228+ * will be the comment leader length sent to open_line().
229 */
230 static void
231 internal_format(textwidth, second_indent, flags, format_only, c)
232***************
233*** 6289,6311 ****
234 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
235 #ifdef FEAT_COMMENTS
236 + (do_comments ? OPENLINE_DO_COM : 0)
237 #endif
238! , old_indent);
239! old_indent = 0;
240
241 replace_offset = 0;
242 if (first_line)
243 {
244! if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
245! second_indent = get_number_indent(curwin->w_cursor.lnum -1);
246! if (second_indent >= 0)
247 {
248 #ifdef FEAT_VREPLACE
249! if (State & VREPLACE_FLAG)
250! change_indent(INDENT_SET, second_indent, FALSE, NUL, TRUE);
251! else
252 #endif
253! (void)set_indent(second_indent, SIN_CHANGED);
254 }
255 first_line = FALSE;
256 }
257--- 6302,6337 ----
258 + (fo_white_par ? OPENLINE_KEEPTRAIL : 0)
259 #ifdef FEAT_COMMENTS
260 + (do_comments ? OPENLINE_DO_COM : 0)
261+ + ((flags & INSCHAR_COM_LIST) ? OPENLINE_COM_LIST : 0)
262 #endif
263! , ((flags & INSCHAR_COM_LIST) ? second_indent : old_indent));
264! if (!(flags & INSCHAR_COM_LIST))
265! old_indent = 0;
266
267 replace_offset = 0;
268 if (first_line)
269 {
270! if (!(flags & INSCHAR_COM_LIST))
271 {
272+ /*
273+ * This section is for numeric lists w/o comments. If comment
274+ * indents are needed with numeric lists (formatoptions=nq),
275+ * then the INSCHAR_COM_LIST flag will cause the corresponding
276+ * OPENLINE_COM_LIST flag to be passed through to open_line()
277+ * (as seen above)...
278+ */
279+ if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
280+ second_indent = get_number_indent(curwin->w_cursor.lnum -1);
281+ if (second_indent >= 0)
282+ {
283 #ifdef FEAT_VREPLACE
284! if (State & VREPLACE_FLAG)
285! change_indent(INDENT_SET, second_indent,
286! FALSE, NUL, TRUE);
287! else
288 #endif
289! (void)set_indent(second_indent, SIN_CHANGED);
290! }
291 }
292 first_line = FALSE;
293 }
294*** ../vim-7.3.551/src/misc1.c 2012-06-13 13:40:45.000000000 +0200
295--- src/misc1.c 2012-06-13 16:54:59.000000000 +0200
296***************
297*** 423,449 ****
298 {
299 colnr_T col;
300 pos_T pos;
301- regmmatch_T regmatch;
302
303 if (lnum > curbuf->b_ml.ml_line_count)
304 return -1;
305 pos.lnum = 0;
306! regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
307! if (regmatch.regprog != NULL)
308 {
309! regmatch.rmm_ic = FALSE;
310! regmatch.rmm_maxcol = 0;
311! if (vim_regexec_multi(&regmatch, curwin, curbuf, lnum,
312! (colnr_T)0, NULL))
313 {
314! pos.lnum = regmatch.endpos[0].lnum + lnum;
315! pos.col = regmatch.endpos[0].col;
316 #ifdef FEAT_VIRTUALEDIT
317! pos.coladd = 0;
318 #endif
319 }
320 vim_free(regmatch.regprog);
321 }
322
323 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
324 return -1;
325--- 423,492 ----
326 {
327 colnr_T col;
328 pos_T pos;
329
330 if (lnum > curbuf->b_ml.ml_line_count)
331 return -1;
332 pos.lnum = 0;
333!
334! #ifdef FEAT_COMMENTS
335! if (has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER))
336 {
337! regmatch_T regmatch;
338! int lead_len; /* length of comment leader */
339!
340! lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
341! regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
342! if (regmatch.regprog != NULL)
343 {
344! regmatch.rm_ic = FALSE;
345!
346! /* vim_regexec() expects a pointer to a line. This lets us
347! * start matching for the flp beyond any comment leader... */
348! if (vim_regexec(&regmatch, ml_get(lnum) + lead_len, (colnr_T)0))
349! {
350! pos.lnum = lnum;
351! pos.col = *regmatch.endp - (ml_get(lnum) + lead_len);
352! pos.col += lead_len;
353 #ifdef FEAT_VIRTUALEDIT
354! pos.coladd = 0;
355 #endif
356+ }
357 }
358 vim_free(regmatch.regprog);
359 }
360+ else
361+ {
362+ /*
363+ * What follows is the orig code that is not "comment aware"...
364+ *
365+ * I'm not sure if regmmatch_T (multi-match) is needed in this case.
366+ * It may be true that this section would work properly using the
367+ * regmatch_T code above, in which case, these two seperate sections
368+ * should be consolidated w/ FEAT_COMMENTS making lead_len > 0...
369+ */
370+ #endif
371+ regmmatch_T regmatch;
372+
373+ regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
374+
375+ if (regmatch.regprog != NULL)
376+ {
377+ regmatch.rmm_ic = FALSE;
378+ regmatch.rmm_maxcol = 0;
379+ if (vim_regexec_multi(&regmatch, curwin, curbuf,
380+ lnum, (colnr_T)0, NULL))
381+ {
382+ pos.lnum = regmatch.endpos[0].lnum + lnum;
383+ pos.col = regmatch.endpos[0].col;
384+ #ifdef FEAT_VIRTUALEDIT
385+ pos.coladd = 0;
386+ #endif
387+ }
388+ vim_free(regmatch.regprog);
389+ }
390+ #ifdef FEAT_COMMENTS
391+ }
392+ #endif
393
394 if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
395 return -1;
396***************
397*** 502,515 ****
398 * OPENLINE_DO_COM format comments
399 * OPENLINE_KEEPTRAIL keep trailing spaces
400 * OPENLINE_MARKFIX adjust mark positions after the line break
401 *
402 * Return TRUE for success, FALSE for failure
403 */
404 int
405! open_line(dir, flags, old_indent)
406 int dir; /* FORWARD or BACKWARD */
407 int flags;
408! int old_indent; /* indent for after ^^D in Insert mode */
409 {
410 char_u *saved_line; /* copy of the original line */
411 char_u *next_line = NULL; /* copy of the next line */
412--- 545,562 ----
413 * OPENLINE_DO_COM format comments
414 * OPENLINE_KEEPTRAIL keep trailing spaces
415 * OPENLINE_MARKFIX adjust mark positions after the line break
416+ * OPENLINE_COM_LIST format comments with list or 2nd line indent
417+ *
418+ * "second_line_indent": indent for after ^^D in Insert mode or if flag
419+ * OPENLINE_COM_LIST
420 *
421 * Return TRUE for success, FALSE for failure
422 */
423 int
424! open_line(dir, flags, second_line_indent)
425 int dir; /* FORWARD or BACKWARD */
426 int flags;
427! int second_line_indent;
428 {
429 char_u *saved_line; /* copy of the original line */
430 char_u *next_line = NULL; /* copy of the next line */
431***************
432*** 650,657 ****
433 * count white space on current line
434 */
435 newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts);
436! if (newindent == 0)
437! newindent = old_indent; /* for ^^D command in insert mode */
438
439 #ifdef FEAT_SMARTINDENT
440 /*
441--- 697,704 ----
442 * count white space on current line
443 */
444 newindent = get_indent_str(saved_line, (int)curbuf->b_p_ts);
445! if (newindent == 0 && !(flags & OPENLINE_COM_LIST))
446! newindent = second_line_indent; /* for ^^D command in insert mode */
447
448 #ifdef FEAT_SMARTINDENT
449 /*
450***************
451*** 1008,1015 ****
452 if (lead_len)
453 {
454 /* allocate buffer (may concatenate p_exta later) */
455! leader = alloc(lead_len + lead_repl_len + extra_space +
456! extra_len + 1);
457 allocated = leader; /* remember to free it later */
458
459 if (leader == NULL)
460--- 1055,1062 ----
461 if (lead_len)
462 {
463 /* allocate buffer (may concatenate p_exta later) */
464! leader = alloc(lead_len + lead_repl_len + extra_space + extra_len
465! + (second_line_indent > 0 ? second_line_indent : 0));
466 allocated = leader; /* remember to free it later */
467
468 if (leader == NULL)
469***************
470*** 1304,1309 ****
471--- 1351,1370 ----
472 /* concatenate leader and p_extra, if there is a leader */
473 if (lead_len)
474 {
475+ if (flags & OPENLINE_COM_LIST && second_line_indent > 0)
476+ {
477+ int i;
478+ int padding = second_line_indent - (newindent + STRLEN(leader));
479+
480+ /* Here whitespace is inserted after the comment char.
481+ * Below, set_indent(newindent, SIN_INSERT) will insert the
482+ * whitespace needed before the comment char. */
483+ for (i = 0; i < padding; i++)
484+ {
485+ STRCAT(leader, " ");
486+ newcol++;
487+ }
488+ }
489 STRCAT(leader, p_extra);
490 p_extra = leader;
491 did_ai = TRUE; /* So truncating blanks works with comments */
492***************
493*** 4966,4973 ****
494 char_u *
495 FullName_save(fname, force)
496 char_u *fname;
497! int force; /* force expansion, even when it already looks
498! like a full path name */
499 {
500 char_u *buf;
501 char_u *new_fname = NULL;
502--- 5027,5034 ----
503 char_u *
504 FullName_save(fname, force)
505 char_u *fname;
506! int force; /* force expansion, even when it already looks
507! * like a full path name */
508 {
509 char_u *buf;
510 char_u *new_fname = NULL;
511*** ../vim-7.3.551/src/testdir/test68.in 2010-10-09 17:21:42.000000000 +0200
512--- src/testdir/test68.in 2012-06-13 15:49:38.000000000 +0200
513***************
514*** 51,56 ****
515--- 51,77 ----
516 }
517
518 STARTTEST
519+ /^{/+1
520+ :set tw=5 fo=qn comments=:#
521+ gwap
522+ ENDTEST
523+
524+ {
525+ # 1 a b
526+ }
527+
528+ STARTTEST
529+ /^{/+1
530+ :set tw=5 fo=q2 comments=:#
531+ gwap
532+ ENDTEST
533+
534+ {
535+ # x
536+ # a b
537+ }
538+
539+ STARTTEST
540 /^{/+2
541 :set tw& fo=a
542 I^^\e
543*** ../vim-7.3.551/src/testdir/test68.ok 2010-10-09 17:21:42.000000000 +0200
544--- src/testdir/test68.ok 2012-06-13 15:49:38.000000000 +0200
545***************
546*** 34,38 ****
547--- 34,50 ----
548 }
549
550
551+ {
552+ # 1 a
553+ # b
554+ }
555+
556+
557+ {
558+ # x a
559+ # b
560+ }
561+
562+
563 { 1aa ^^2bb }
564
565*** ../vim-7.3.551/src/version.c 2012-06-13 14:28:16.000000000 +0200
566--- src/version.c 2012-06-13 16:36:14.000000000 +0200
567***************
568*** 716,717 ****
569--- 716,719 ----
570 { /* Add new patch number below this line */
571+ /**/
572+ 552,
573 /**/
574
575--
576hundred-and-one symptoms of being an internet addict:
57731. You code your homework in HTML and give your instructor the URL.
578
579 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
580/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
581\\\ an exciting new programming language -- http://www.Zimbu.org ///
582 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
This page took 0.089552 seconds and 4 git commands to generate.