0
0
mirror of https://github.com/vim/vim.git synced 2025-07-26 11:04:33 -04:00

updated for version 7.3.576

Problem:    Formatting of lists inside comments is not right yet.
Solution:   Use another solution and add a test. (Tor Perkins)
This commit is contained in:
Bram Moolenaar 2012-06-29 15:04:49 +02:00
parent 89f940fcac
commit 96b7ca5142
4 changed files with 67 additions and 54 deletions

View File

@ -6320,14 +6320,15 @@ internal_format(textwidth, second_indent, flags, format_only, c)
if (!(flags & INSCHAR_COM_LIST)) if (!(flags & INSCHAR_COM_LIST))
{ {
/* /*
* This section is for numeric lists w/o comments. If comment * This section is for auto-wrap of numeric lists. When not
* indents are needed with numeric lists (formatoptions=nq), * in insert mode (i.e. format_lines()), the INSCHAR_COM_LIST
* then the INSCHAR_COM_LIST flag will cause the corresponding * flag will be set and open_line() will handle it (as seen
* OPENLINE_COM_LIST flag to be passed through to open_line() * above). The code here (and in get_number_indent()) will
* (as seen above)... * recognize comments if needed...
*/ */
if (second_indent < 0 && has_format_option(FO_Q_NUMBER)) if (second_indent < 0 && has_format_option(FO_Q_NUMBER))
second_indent = get_number_indent(curwin->w_cursor.lnum -1); second_indent =
get_number_indent(curwin->w_cursor.lnum - 1);
if (second_indent >= 0) if (second_indent >= 0)
{ {
#ifdef FEAT_VREPLACE #ifdef FEAT_VREPLACE
@ -6335,8 +6336,32 @@ internal_format(textwidth, second_indent, flags, format_only, c)
change_indent(INDENT_SET, second_indent, change_indent(INDENT_SET, second_indent,
FALSE, NUL, TRUE); FALSE, NUL, TRUE);
else else
#endif
#ifdef FEAT_COMMENTS
if (leader_len > 0 && second_indent - leader_len > 0)
{
int i;
int padding = second_indent - leader_len;
/* We started at the first_line of a numbered list
* that has a comment. the open_line() function has
* inserted the proper comment leader and positioned
* the cursor at the end of the split line. Now we
* add the additional whitespace needed after the
* comment leader for the numbered list. */
for (i = 0; i < padding; i++)
{
ins_str((char_u *)" ");
changed_bytes(curwin->w_cursor.lnum, leader_len);
}
}
else
{
#endif #endif
(void)set_indent(second_indent, SIN_CHANGED); (void)set_indent(second_indent, SIN_CHANGED);
#ifdef FEAT_COMMENTS
}
#endif
} }
} }
first_line = FALSE; first_line = FALSE;

View File

@ -424,17 +424,18 @@ get_number_indent(lnum)
colnr_T col; colnr_T col;
pos_T pos; pos_T pos;
regmatch_T regmatch;
int lead_len = 0; /* length of comment leader */
if (lnum > curbuf->b_ml.ml_line_count) if (lnum > curbuf->b_ml.ml_line_count)
return -1; return -1;
pos.lnum = 0; pos.lnum = 0;
#ifdef FEAT_COMMENTS #ifdef FEAT_COMMENTS
if (has_format_option(FO_Q_COMS) && has_format_option(FO_Q_NUMBER)) /* In format_lines() (i.e. not insert mode), fo+=q is needed too... */
{ if ((State & INSERT) || has_format_option(FO_Q_COMS))
regmatch_T regmatch;
int lead_len; /* length of comment leader */
lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE); lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);
#endif
regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC); regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
if (regmatch.regprog != NULL) if (regmatch.regprog != NULL)
{ {
@ -452,40 +453,6 @@ get_number_indent(lnum)
} }
} }
vim_free(regmatch.regprog); vim_free(regmatch.regprog);
}
else
{
/*
* What follows is the orig code that is not "comment aware"...
*
* I'm not sure if regmmatch_T (multi-match) is needed in this case.
* It may be true that this section would work properly using the
* regmatch_T code above, in which case, these two separate sections
* should be consolidated w/ FEAT_COMMENTS making lead_len > 0...
*/
#endif
regmmatch_T regmatch;
regmatch.regprog = vim_regcomp(curbuf->b_p_flp, RE_MAGIC);
if (regmatch.regprog != NULL)
{
regmatch.rmm_ic = FALSE;
regmatch.rmm_maxcol = 0;
if (vim_regexec_multi(&regmatch, curwin, curbuf,
lnum, (colnr_T)0, NULL))
{
pos.lnum = regmatch.endpos[0].lnum + lnum;
pos.col = regmatch.endpos[0].col;
#ifdef FEAT_VIRTUALEDIT
pos.coladd = 0;
#endif
}
vim_free(regmatch.regprog);
}
#ifdef FEAT_COMMENTS
}
#endif
if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL) if (pos.lnum == 0 || *ml_get_pos(&pos) == NUL)
return -1; return -1;

View File

@ -50,6 +50,17 @@ a b
#a b #a b
} }
STARTTEST
/^{/+1
:set tw=5 fo=tcn comments=:#
A bjA b
ENDTEST
{
1 a
# 1 a
}
STARTTEST STARTTEST
/^{/+1 /^{/+1
:set tw=5 fo=qn comments=:# :set tw=5 fo=qn comments=:#
@ -82,6 +93,14 @@ ENDTEST
2bb 2bb
} }
STARTTEST
/^#/
:setl tw=12 fo=tqnc comments=:#
A foobar
ENDTEST
# 1 xxxxx
STARTTEST STARTTEST
:g/^STARTTEST/.,/^ENDTEST/d :g/^STARTTEST/.,/^ENDTEST/d
:1;/^Results/,$wq! test.out :1;/^Results/,$wq! test.out

View File

@ -714,6 +714,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
576,
/**/ /**/
575, 575,
/**/ /**/