Patch: fo=q (comments) w/ n (num list) or 2 (2nd line) indent

26 views
Skip to first unread message

Tor Perkins

unread,
Jun 5, 2012, 11:01:57 PM6/5/12
to vim...@googlegroups.com

Greetings all,

Given these settings:

:set tw=20
:set formatoptions=tcq2
:set smartindent

... and given this text:

NOTE: blah blah
blah blah

# NOTE: blah blah
# blah blah

If I do gq{motion} on the top paragraph, formatting is unchanged (as
expected), however, gq{motion} (or gwap) on the bottom paragraph
results in this new formatting:

# NOTE: blah blah
# blah blah

So, even though I have both the 2 and q formatoptions, the second
line's indentation is not used when within a comment block...

The t and c formatoptions (for auto-wrap) are working properly with
formatoptions+=2 in both paragraphs.

I would prefer for Vim to be consistent; in this case, I think it
should handle auto-wrap and formatting in the same way. So...
I've made a patch!

The patch applies against version 7.3.538 and doesn't mess with
the auto-wrap logic (it's working!). It does mess with these funcs:

format_lines()
insertchar()
internal_format()
open_line()

The patch also fixes numeric list handling within comments (not just
2nd line indenting)...

I've tried my best to "tread lightly" and comment things pretty well.

I've run "make test" and it is OK. I've also added two new tests to
the "test suite"...

I've attached the patch separately to preserve white space, etc..

Finally, below I include a more complex test case that showcases what
this patch can do (I hope it will be accepted by Bram)...

Thanks for your time and consideration, and thanks for Vim!

- Tor

PS - more test cases here:

== numbered list formatting ======================

vi:tw=25:formatoptions=tcqn:smartindent

11 aaaa aaaa aaaa bbbb bbbb bbbb

22 aaaa aaaa aaaa bbbb
bbbb bbbb

33 aaaa aaaa
aaaa bbbb bbbb bbbb

# 11 aaaa aaaa aaaa bbbb bbbb bbbb

# 22 aaaa aaaa aaaa bbbb
# bbbb bbbb

# 33 aaaa aaaa
# aaaa bbbb bbbb bbbb

> > 11 aaaa aaaa aaaa bbbb bbbb bbbb

> > 22 aaaa aaaa aaaa bbbb
> > bbbb bbbb

> > 33 aaaa aaaa
> > aaaa bbbb bbbb bbbb

-- above = before, below = after --

11 aaaa aaaa aaaa
bbbb bbbb bbbb

22 aaaa aaaa aaaa
bbbb bbbb bbbb

33 aaaa aaaa aaaa
bbbb bbbb bbbb

# 11 aaaa aaaa aaaa
# bbbb bbbb bbbb

# 22 aaaa aaaa aaaa
# bbbb bbbb bbbb

# 33 aaaa aaaa aaaa
# bbbb bbbb bbbb

> > 11 aaaa aaaa aaaa
> > bbbb bbbb bbbb

> > 22 aaaa aaaa aaaa
> > bbbb bbbb bbbb

> > 33 aaaa aaaa aaaa
> > bbbb bbbb bbbb

== 2nd line indent formatting ====================

vi:tw=25:formatoptions=tcq2:smartindent

xx aaaa aaaa aaaa bbbb
bbbb bbbb

xx aaaa aaaa
aaaa bbbb bbbb bbbb

# xx aaaa aaaa aaaa bbbb
# bbbb bbbb

# xx aaaa aaaa
# aaaa bbbb bbbb bbbb

> > xx aaaa aaaa aaaa bbbb
> > bbbb bbbb

> > xx aaaa aaaa
> > aaaa bbbb bbbb bbbb

-- above = before, below = after --

xx aaaa aaaa aaaa
bbbb bbbb bbbb

xx aaaa aaaa aaaa
bbbb bbbb bbbb

# xx aaaa aaaa aaaa
# bbbb bbbb bbbb

# xx aaaa aaaa aaaa
# bbbb bbbb bbbb

> > xx aaaa aaaa aaaa
> > bbbb bbbb bbbb

> > xx aaaa aaaa aaaa
> > bbbb bbbb bbbb

vim_q_n_2.diff

Tor Perkins

unread,
Jun 6, 2012, 12:12:32 PM6/6/12
to vim...@googlegroups.com
> Thanks for your time and consideration, and thanks for Vim!
>
> - Tor

I've updated my patch so that it now applies to 7.3.543 without any
fuzz (please find attached). The only substantive change was:

lead_len = get_leader_len(ml_get(lnum), NULL, FALSE);

becomes...

lead_len = get_leader_len(ml_get(lnum), NULL, FALSE, TRUE);

Thanks!

- Tor

PS - I really like the new fo+=j patch that came w/ 7.3.541... :^)

vim_q_n_2.diff
Reply all
Reply to author
Forward
0 new messages