Skip to content

Commit 4a0b85a

Browse files
chrisbrabrammool
authored andcommitted
patch 8.2.3160: 'breakindent' does not work well for bulleted lists
Problem: 'breakindent' does not work well for bulleted and numbered lists. Solution: Add the "list" entry to 'breakindentopt'. (Christian Brabandt, closes #8564, closes #1661)
1 parent 5bea41d commit 4a0b85a

File tree

5 files changed

+100
-1
lines changed

5 files changed

+100
-1
lines changed

runtime/doc/options.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,10 @@ 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-
The default value for min is 20 and shift is 0.
1329+
list:{n} Adds an additional indent for lines that match a
1330+
numbered or bulleted list (using the
1331+
'formatlistpat' setting).
1332+
The default value for min is 20, shift and list is 0.
13301333

13311334
*'browsedir'* *'bsdir'*
13321335
'browsedir' 'bsdir' string (default: "last")

src/indent.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,7 @@ briopt_check(win_T *wp)
854854
int bri_shift = 0;
855855
long bri_min = 20;
856856
int bri_sbr = FALSE;
857+
int bri_list = 0;
857858

858859
p = wp->w_p_briopt;
859860
while (*p != NUL)
@@ -874,6 +875,11 @@ briopt_check(win_T *wp)
874875
p += 3;
875876
bri_sbr = TRUE;
876877
}
878+
else if (STRNCMP(p, "list:", 5) == 0)
879+
{
880+
p += 5;
881+
bri_list = getdigits(&p);
882+
}
877883
if (*p != ',' && *p != NUL)
878884
return FAIL;
879885
if (*p == ',')
@@ -883,6 +889,7 @@ briopt_check(win_T *wp)
883889
wp->w_briopt_shift = bri_shift;
884890
wp->w_briopt_min = bri_min;
885891
wp->w_briopt_sbr = bri_sbr;
892+
wp->w_briopt_list = bri_list;
886893

887894
return OK;
888895
}
@@ -941,9 +948,25 @@ get_breakindent_win(
941948
// Add offset for number column, if 'n' is in 'cpoptions'
942949
bri += win_col_off2(wp);
943950

951+
// add additional indent for numbered lists
952+
if (wp->w_briopt_list > 0)
953+
{
954+
regmatch_T regmatch;
955+
956+
regmatch.regprog = vim_regcomp(curbuf->b_p_flp,
957+
RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT);
958+
if (regmatch.regprog != NULL)
959+
{
960+
if (vim_regexec(&regmatch, line, 0))
961+
bri += wp->w_briopt_list;
962+
vim_regfree(regmatch.regprog);
963+
}
964+
}
965+
944966
// never indent past left window margin
945967
if (bri < 0)
946968
bri = 0;
969+
947970
// always leave at least bri_min characters on the left,
948971
// if text width is sufficient
949972
else if (bri > eff_wwidth - wp->w_briopt_min)

src/structs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3671,6 +3671,7 @@ struct window_S
36713671
int w_briopt_min; // minimum width for breakindent
36723672
int w_briopt_shift; // additional shift for breakindent
36733673
int w_briopt_sbr; // sbr in 'briopt'
3674+
int w_briopt_list; // additional indent for lists
36743675
#endif
36753676

36763677
// transform a pointer to a "onebuf" option into a "allbuf" option

src/testdir/test_breakindent.vim

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ func s:screen_lines(lnum, width) abort
1515
return ScreenLines([a:lnum, a:lnum + 2], a:width)
1616
endfunc
1717

18+
func s:screen_lines2(lnums, lnume, width) abort
19+
return ScreenLines([a:lnums, a:lnume], a:width)
20+
endfunc
21+
1822
func s:compare_lines(expect, actual)
1923
call assert_equal(join(a:expect, "\n"), join(a:actual, "\n"))
2024
endfunc
@@ -708,4 +712,70 @@ func Test_breakindent20_cpo_n_nextpage()
708712
call s:close_windows('set breakindent& briopt& cpo& number&')
709713
endfunc
710714

715+
func Test_breakindent20_list()
716+
call s:test_windows('setl breakindent breakindentopt= linebreak')
717+
" default:
718+
call setline(1, [' 1. Congress shall make no law',
719+
\ ' 2.) Congress shall make no law',
720+
\ ' 3.] Congress shall make no law'])
721+
norm! 1gg
722+
redraw!
723+
let lines = s:screen_lines2(1, 6, 20)
724+
let expect = [
725+
\ " 1. Congress ",
726+
\ "shall make no law ",
727+
\ " 2.) Congress ",
728+
\ "shall make no law ",
729+
\ " 3.] Congress ",
730+
\ "shall make no law ",
731+
\ ]
732+
call s:compare_lines(expect, lines)
733+
" set mininum indent
734+
setl briopt=min:5
735+
redraw!
736+
let lines = s:screen_lines2(1, 6, 20)
737+
let expect = [
738+
\ " 1. Congress ",
739+
\ " shall make no law ",
740+
\ " 2.) Congress ",
741+
\ " shall make no law ",
742+
\ " 3.] Congress ",
743+
\ " shall make no law ",
744+
\ ]
745+
call s:compare_lines(expect, lines)
746+
" set additional handing indent
747+
setl briopt+=list:4
748+
redraw!
749+
let expect = [
750+
\ " 1. Congress ",
751+
\ " shall make no ",
752+
\ " law ",
753+
\ " 2.) Congress ",
754+
\ " shall make no ",
755+
\ " law ",
756+
\ " 3.] Congress ",
757+
\ " shall make no ",
758+
\ " law ",
759+
\ ]
760+
let lines = s:screen_lines2(1, 9, 20)
761+
call s:compare_lines(expect, lines)
762+
" reset linebreak option
763+
" Note: it indents by one additional
764+
" space, because of the leading space.
765+
setl linebreak&vim list listchars=eol:$,space:_
766+
redraw!
767+
let expect = [
768+
\ "__1.__Congress_shall",
769+
\ " _make_no_law$ ",
770+
\ "__2.)_Congress_shall",
771+
\ " _make_no_law$ ",
772+
\ "__3.]_Congress_shall",
773+
\ " _make_no_law$ ",
774+
\ ]
775+
let lines = s:screen_lines2(1, 6, 20)
776+
call s:compare_lines(expect, lines)
777+
778+
call s:close_windows('set breakindent& briopt& linebreak& list& listchars&')
779+
endfunc
780+
711781
" 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+
3160,
758760
/**/
759761
3159,
760762
/**/

0 commit comments

Comments
 (0)