]> granicus.if.org Git - vim/commitdiff
patch 8.2.3198: cannot use 'formatlistpat' for breakindent v8.2.3198
authorMaxim Kim <habamax@gmail.com>
Thu, 22 Jul 2021 09:46:59 +0000 (11:46 +0200)
committerBram Moolenaar <Bram@vim.org>
Thu, 22 Jul 2021 09:46:59 +0000 (11:46 +0200)
Problem:    Cannot use 'formatlistpat' for breakindent.
Solution:   Use a negative list indent. (Maxim Kim, closes #8594)

runtime/doc/options.txt
src/indent.c
src/testdir/test_breakindent.vim
src/version.c

index aaac094884e66cccabf975a032d92d1edde985d4..e5a76b767736b18853c4f10ee743449b5760f657 100644 (file)
@@ -1326,9 +1326,11 @@ A jump table for the options with a short description can be found at |Q_op|.
                            continuation (positive).
                sbr         Display the 'showbreak' value before applying the
                            additional indent.
-               list:{n}    Adds an additional indent for lines that match a 
+               list:{n}    Adds an additional indent for lines that match a
                            numbered or bulleted list (using the
                            'formatlistpat' setting).
+               list:-1     Uses the length of a match with 'formatlistpat'
+                           for indentation.
        The default value for min is 20, shift and list is 0.
 
                                                *'browsedir'* *'bsdir'*
index cf07f4af6e7fab3c0e61926a080da28c17b24c2c..ed7ce97f150538ee1fbee2e6df3ca362ccba3aec 100644 (file)
@@ -941,15 +941,11 @@ get_breakindent_win(
     }
     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 @@ get_breakindent_win(
        if (regmatch.regprog != NULL)
        {
            if (vim_regexec(&regmatch, 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;
index bfca06aec07fc4abfe7a00e1aafa1c0fde60b485..4dab8b598fb43a0b5835d638a318fc11f3c24b17 100644 (file)
@@ -759,6 +759,7 @@ func Test_breakindent20_list()
        \ ]
   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 @@ func Test_breakindent20_list()
   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
index 027de07b3f63b67d6c7f37e3fee0e48f04d8d99c..631c1220019d4ec89fb0e856ba7ef97d19b8e32d 100644 (file)
@@ -755,6 +755,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    3198,
 /**/
     3197,
 /**/