Skip to content

Commit f674b35

Browse files
habamaxbrammool
authored andcommitted
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)
1 parent d8e4447 commit f674b35

File tree

4 files changed

+71
-8
lines changed

4 files changed

+71
-8
lines changed

runtime/doc/options.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,9 +1326,11 @@ A jump table for the options with a short description can be found at |Q_op|.
13261326
continuation (positive).
13271327
sbr Display the 'showbreak' value before applying the
13281328
additional indent.
1329-
list:{n} Adds an additional indent for lines that match a
1329+
list:{n} Adds an additional indent for lines that match a
13301330
numbered or bulleted list (using the
13311331
'formatlistpat' setting).
1332+
list:-1 Uses the length of a match with 'formatlistpat'
1333+
for indentation.
13321334
The default value for min is 20, shift and list is 0.
13331335

13341336
*'browsedir'* *'bsdir'*

src/indent.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -941,15 +941,11 @@ get_breakindent_win(
941941
}
942942
bri = prev_indent + wp->w_briopt_shift;
943943

944-
// indent minus the length of the showbreak string
945-
if (wp->w_briopt_sbr)
946-
bri -= vim_strsize(get_showbreak_value(wp));
947-
948944
// Add offset for number column, if 'n' is in 'cpoptions'
949945
bri += win_col_off2(wp);
950946

951947
// add additional indent for numbered lists
952-
if (wp->w_briopt_list > 0)
948+
if (wp->w_briopt_list != 0)
953949
{
954950
regmatch_T regmatch;
955951

@@ -958,11 +954,21 @@ get_breakindent_win(
958954
if (regmatch.regprog != NULL)
959955
{
960956
if (vim_regexec(&regmatch, line, 0))
961-
bri += wp->w_briopt_list;
957+
{
958+
if (wp->w_briopt_list > 0)
959+
bri += wp->w_briopt_list;
960+
else
961+
bri = (*regmatch.endp - *regmatch.startp);
962+
}
962963
vim_regfree(regmatch.regprog);
963964
}
964965
}
965966

967+
// indent minus the length of the showbreak string
968+
if (wp->w_briopt_sbr)
969+
bri -= vim_strsize(get_showbreak_value(wp));
970+
971+
966972
// never indent past left window margin
967973
if (bri < 0)
968974
bri = 0;

src/testdir/test_breakindent.vim

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,7 @@ func Test_breakindent20_list()
759759
\ ]
760760
let lines = s:screen_lines2(1, 9, 20)
761761
call s:compare_lines(expect, lines)
762+
762763
" reset linebreak option
763764
" Note: it indents by one additional
764765
" space, because of the leading space.
@@ -775,7 +776,59 @@ func Test_breakindent20_list()
775776
let lines = s:screen_lines2(1, 6, 20)
776777
call s:compare_lines(expect, lines)
777778

778-
call s:close_windows('set breakindent& briopt& linebreak& list& listchars&')
779+
" check formatlistpat indent
780+
setl briopt=min:5,list:-1
781+
setl linebreak list&vim listchars&vim
782+
let &l:flp = '^\s*\d\+\.\?[\]:)}\t ]\s*'
783+
redraw!
784+
let expect = [
785+
\ " 1. Congress ",
786+
\ " shall make no ",
787+
\ " law ",
788+
\ " 2.) Congress ",
789+
\ " shall make no ",
790+
\ " law ",
791+
\ " 3.] Congress ",
792+
\ " shall make no ",
793+
\ " law ",
794+
\ ]
795+
let lines = s:screen_lines2(1, 9, 20)
796+
call s:compare_lines(expect, lines)
797+
" check formatlistpat indent with different list levels
798+
let &l:flp = '^\s*\*\+\s\+'
799+
redraw!
800+
%delete _
801+
call setline(1, ['* Congress shall make no law',
802+
\ '*** Congress shall make no law',
803+
\ '**** Congress shall make no law'])
804+
norm! 1gg
805+
let expect = [
806+
\ "* Congress shall ",
807+
\ " make no law ",
808+
\ "*** Congress shall ",
809+
\ " make no law ",
810+
\ "**** Congress shall ",
811+
\ " make no law ",
812+
\ ]
813+
let lines = s:screen_lines2(1, 6, 20)
814+
call s:compare_lines(expect, lines)
815+
816+
" check formatlistpat indent with different list level
817+
" showbreak and sbr
818+
setl briopt=min:5,sbr,list:-1,shift:2
819+
setl showbreak=>
820+
redraw!
821+
let expect = [
822+
\ "* Congress shall ",
823+
\ "> make no law ",
824+
\ "*** Congress shall ",
825+
\ "> make no law ",
826+
\ "**** Congress shall ",
827+
\ "> make no law ",
828+
\ ]
829+
let lines = s:screen_lines2(1, 6, 20)
830+
call s:compare_lines(expect, lines)
831+
call s:close_windows('set breakindent& briopt& linebreak& list& listchars& showbreak&')
779832
endfunc
780833

781834
" vim: shiftwidth=2 sts=2 expandtab

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,8 @@ static char *(features[]) =
755755

756756
static int included_patches[] =
757757
{ /* Add new patch number below this line */
758+
/**/
759+
3198,
758760
/**/
759761
3197,
760762
/**/

0 commit comments

Comments
 (0)