Skip to content

Commit 61a6ac4

Browse files
zeertzjqchrisbra
authored andcommitted
patch 9.1.0720: Wrong breakindentopt=list:-1 with multibyte or TABs
Problem: Wrong breakindentopt=list:-1 with multibyte chars or TABs in text matched by 'formatlistpat' (John M Devin) Solution: Use the width of the match text (zeertzjq) fixes: #15634 closes: #15635 Signed-off-by: zeertzjq <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 66f65a4 commit 61a6ac4

6 files changed

Lines changed: 83 additions & 11 deletions

File tree

runtime/doc/options.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*options.txt* For Vim version 9.1. Last change: 2024 Aug 12
1+
*options.txt* For Vim version 9.1. Last change: 2024 Sep 07
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1491,9 +1491,9 @@ A jump table for the options with a short description can be found at |Q_op|.
14911491
list:{n} Adds an additional indent for lines that match a
14921492
numbered or bulleted list (using the
14931493
'formatlistpat' setting).
1494-
list:-1 Uses the length of a match with 'formatlistpat'
1495-
for indentation.
14961494
(default: 0)
1495+
list:-1 Uses the width of a match with 'formatlistpat' for
1496+
indentation.
14971497
column:{n} Indent at column {n}. Will overrule the other
14981498
sub-options. Note: an additional indent may be
14991499
added for the 'showbreak' setting.

src/charset.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,8 @@ chartabsize(char_u *p, colnr_T col)
739739
RET_WIN_BUF_CHARTABSIZE(curwin, curbuf, p, col)
740740
}
741741

742-
#ifdef FEAT_LINEBREAK
743-
static int
742+
#if defined(FEAT_LINEBREAK) || defined(PROTO)
743+
int
744744
win_chartabsize(win_T *wp, char_u *p, colnr_T col)
745745
{
746746
RET_WIN_BUF_CHARTABSIZE(wp, wp->w_buffer, p, col)

src/indent.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,21 @@ get_breakindent_win(
10211021
if (wp->w_briopt_list > 0)
10221022
prev_list = wp->w_briopt_list;
10231023
else
1024-
prev_indent = (*regmatch.endp - *regmatch.startp);
1024+
{
1025+
char_u *ptr = *regmatch.startp;
1026+
char_u *end_ptr = *regmatch.endp;
1027+
int indent = 0;
1028+
1029+
// Compute the width of the matched text.
1030+
// Use win_chartabsize() so that TAB size is correct,
1031+
// while wrapping is ignored.
1032+
while (ptr < end_ptr)
1033+
{
1034+
indent += win_chartabsize(wp, ptr, indent);
1035+
MB_PTR_ADV(ptr);
1036+
}
1037+
prev_indent = indent;
1038+
}
10251039
}
10261040
vim_regfree(regmatch.regprog);
10271041
}

src/proto/charset.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int ptr2cells(char_u *p);
1616
int vim_strsize(char_u *s);
1717
int vim_strnsize(char_u *s, int len);
1818
int chartabsize(char_u *p, colnr_T col);
19+
int win_chartabsize(win_T *wp, char_u *p, colnr_T col);
1920
int linetabsize_str(char_u *s);
2021
int linetabsize_col(int startcol, char_u *s);
2122
int win_linetabsize(win_T *wp, linenr_T lnum, char_u *line, colnr_T len);

src/testdir/test_breakindent.vim

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -797,18 +797,73 @@ func Test_breakindent20_list()
797797
\ ]
798798
let lines = s:screen_lines2(1, 9, 20)
799799
call s:compare_lines(expect, lines)
800+
801+
" check with TABs
802+
call setline(1, ["\t1.\tCongress shall make no law",
803+
\ "\t2.) Congress shall make no law",
804+
\ "\t3.] Congress shall make no law"])
805+
setl tabstop=4 list listchars=tab:<->
806+
norm! 1gg
807+
redraw!
808+
let expect = [
809+
\ "<-->1.<>Congress ",
810+
\ " shall make ",
811+
\ " no law ",
812+
\ "<-->2.) Congress ",
813+
\ " shall make ",
814+
\ " no law ",
815+
\ "<-->3.] Congress ",
816+
\ " shall make ",
817+
\ " no law ",
818+
\ ]
819+
let lines = s:screen_lines2(1, 9, 20)
820+
call s:compare_lines(expect, lines)
821+
822+
setl tabstop=2 nolist
823+
redraw!
824+
let expect = [
825+
\ " 1. Congress ",
826+
\ " shall make no ",
827+
\ " law ",
828+
\ " 2.) Congress ",
829+
\ " shall make no ",
830+
\ " law ",
831+
\ " 3.] Congress ",
832+
\ " shall make no ",
833+
\ " law ",
834+
\ ]
835+
let lines = s:screen_lines2(1, 9, 20)
836+
call s:compare_lines(expect, lines)
837+
838+
setl tabstop& list listchars=space:_
839+
redraw!
840+
let expect = [
841+
\ "^I1.^ICongress_ ",
842+
\ " shall_make_no_",
843+
\ " law ",
844+
\ "^I2.)_Congress_ ",
845+
\ " shall_make_no_",
846+
\ " law ",
847+
\ "^I3.]_Congress_ ",
848+
\ " shall_make_no_",
849+
\ " law ",
850+
\ ]
851+
let lines = s:screen_lines2(1, 9, 20)
852+
call s:compare_lines(expect, lines)
853+
800854
" check formatlistpat indent with different list levels
801-
let &l:flp = '^\s*\*\+\s\+'
855+
let &l:flp = '^\s*\(\*\|•\)\+\s\+'
856+
setl list&vim listchars&vim
802857
%delete _
803858
call setline(1, ['* Congress shall make no law',
804-
\ '*** Congress shall make no law',
859+
\ '••• Congress shall make no law',
805860
\ '**** Congress shall make no law'])
806861
norm! 1gg
807862
redraw!
808863
let expect = [
809864
\ "* Congress shall ",
810865
\ " make no law ",
811-
\ "*** Congress shall ",
866+
\ "••• Congress shall ",
812867
\ " make no law ",
813868
\ "**** Congress shall ",
814869
\ " make no law ",
@@ -824,7 +879,7 @@ func Test_breakindent20_list()
824879
let expect = [
825880
\ "* Congress shall ",
826881
\ "> make no law ",
827-
\ "*** Congress shall ",
882+
\ "••• Congress shall ",
828883
\ "> make no law ",
829884
\ "**** Congress shall ",
830885
\ "> make no law ",
@@ -840,7 +895,7 @@ func Test_breakindent20_list()
840895
let expect = [
841896
\ "* Congress shall ",
842897
\ "> make no law ",
843-
\ "*** Congress shall ",
898+
\ "••• Congress shall ",
844899
\ "> make no law ",
845900
\ "**** Congress shall ",
846901
\ "> make no law ",

src/version.c

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

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
720,
707709
/**/
708710
719,
709711
/**/

0 commit comments

Comments
 (0)