patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Problem: Cannot use 'formatlistpat' for breakindent.
Solution: Use a negative list indent. (Maxim Kim, closes #8594)
diff --git a/src/indent.c b/src/indent.c
index cf07f4a..ed7ce97 100644
--- a/src/indent.c
+++ b/src/indent.c
@@ -941,15 +941,11 @@
}
bri = prev_indent + wp->w_briopt_shift;
- // indent minus the length of the showbreak string
- if (wp->w_briopt_sbr)
- bri -= vim_strsize(get_showbreak_value(wp));
-
// Add offset for number column, if 'n' is in 'cpoptions'
bri += win_col_off2(wp);
// add additional indent for numbered lists
- if (wp->w_briopt_list > 0)
+ if (wp->w_briopt_list != 0)
{
regmatch_T regmatch;
@@ -958,11 +954,21 @@
if (regmatch.regprog != NULL)
{
if (vim_regexec(®match, line, 0))
- bri += wp->w_briopt_list;
+ {
+ if (wp->w_briopt_list > 0)
+ bri += wp->w_briopt_list;
+ else
+ bri = (*regmatch.endp - *regmatch.startp);
+ }
vim_regfree(regmatch.regprog);
}
}
+ // indent minus the length of the showbreak string
+ if (wp->w_briopt_sbr)
+ bri -= vim_strsize(get_showbreak_value(wp));
+
+
// never indent past left window margin
if (bri < 0)
bri = 0;
diff --git a/src/testdir/test_breakindent.vim b/src/testdir/test_breakindent.vim
index bfca06a..4dab8b5 100644
--- a/src/testdir/test_breakindent.vim
+++ b/src/testdir/test_breakindent.vim
@@ -759,6 +759,7 @@
\ ]
let lines = s:screen_lines2(1, 9, 20)
call s:compare_lines(expect, lines)
+
" reset linebreak option
" Note: it indents by one additional
" space, because of the leading space.
@@ -775,7 +776,59 @@
let lines = s:screen_lines2(1, 6, 20)
call s:compare_lines(expect, lines)
- call s:close_windows('set breakindent& briopt& linebreak& list& listchars&')
+ " check formatlistpat indent
+ setl briopt=min:5,list:-1
+ setl linebreak list&vim listchars&vim
+ let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
+ redraw!
+ let expect = [
+ \ " 1. Congress ",
+ \ " shall make no ",
+ \ " law ",
+ \ " 2.) Congress ",
+ \ " shall make no ",
+ \ " law ",
+ \ " 3.] Congress ",
+ \ " shall make no ",
+ \ " law ",
+ \ ]
+ let lines = s:screen_lines2(1, 9, 20)
+ call s:compare_lines(expect, lines)
+ " check formatlistpat indent with different list levels
+ let &l:flp = '^\s*\*\+\s\+'
+ redraw!
+ %delete _
+ call setline(1, ['* Congress shall make no law',
+ \ '*** Congress shall make no law',
+ \ '**** Congress shall make no law'])
+ norm! 1gg
+ let expect = [
+ \ "* Congress shall ",
+ \ " make no law ",
+ \ "*** Congress shall ",
+ \ " make no law ",
+ \ "**** Congress shall ",
+ \ " make no law ",
+ \ ]
+ let lines = s:screen_lines2(1, 6, 20)
+ call s:compare_lines(expect, lines)
+
+ " check formatlistpat indent with different list level
+ " showbreak and sbr
+ setl briopt=min:5,sbr,list:-1,shift:2
+ setl showbreak=>
+ redraw!
+ let expect = [
+ \ "* Congress shall ",
+ \ "> make no law ",
+ \ "*** Congress shall ",
+ \ "> make no law ",
+ \ "**** Congress shall ",
+ \ "> make no law ",
+ \ ]
+ let lines = s:screen_lines2(1, 6, 20)
+ call s:compare_lines(expect, lines)
+ call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
endfunc
" vim: shiftwidth=2 sts=2 expandtab
diff --git a/src/version.c b/src/version.c
index 027de07..631c122 100644
--- a/src/version.c
+++ b/src/version.c
@@ -756,6 +756,8 @@
static int included_patches[] =
{ /* Add new patch number below this line */
/**/
+ 3198,
+/**/
3197,
/**/
3196,