• R/O
  • SSH

vim: Commit

Mirror of the Vim source from https://github.com/vim/vim


Commit MetaInfo

Revisionb3d7becabe99810daf0ece083401921f316d114d (tree)
Time2021-07-22 19:00:05
AuthorBram Moolenaar <Bram@vim....>
CommiterBram Moolenaar

Log Message

patch 8.2.3198: cannot use 'formatlistpat' for breakindent

Commit: https://github.com/vim/vim/commit/f674b358fc18cf1641a066cc5de73da69e651024
Author: Maxim Kim <habamax@gmail.com>
Date: Thu Jul 22 11:46:59 2021 +0200

patch 8.2.3198: cannot use 'formatlistpat' for breakindent
Problem: Cannot use 'formatlistpat' for breakindent.
Solution: Use a negative list indent. (Maxim Kim, closes https://github.com/vim/vim/issues/8594)

Change Summary

Incremental Difference

diff -r e99639cf8f64 -r b3d7becabe99 runtime/doc/options.txt
--- a/runtime/doc/options.txt Wed Jul 21 22:30:06 2021 +0200
+++ b/runtime/doc/options.txt Thu Jul 22 12:00:05 2021 +0200
@@ -1326,9 +1326,11 @@
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'*
diff -r e99639cf8f64 -r b3d7becabe99 src/indent.c
--- a/src/indent.c Wed Jul 21 22:30:06 2021 +0200
+++ b/src/indent.c Thu Jul 22 12:00:05 2021 +0200
@@ -941,15 +941,11 @@
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 @@
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;
diff -r e99639cf8f64 -r b3d7becabe99 src/testdir/test_breakindent.vim
--- a/src/testdir/test_breakindent.vim Wed Jul 21 22:30:06 2021 +0200
+++ b/src/testdir/test_breakindent.vim Thu Jul 22 12:00:05 2021 +0200
@@ -759,6 +759,7 @@
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 @@
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
diff -r e99639cf8f64 -r b3d7becabe99 src/version.c
--- a/src/version.c Wed Jul 21 22:30:06 2021 +0200
+++ b/src/version.c Thu Jul 22 12:00:05 2021 +0200
@@ -756,6 +756,8 @@
756756 static int included_patches[] =
757757 { /* Add new patch number below this line */
758758 /**/
759+ 3198,
760+/**/
759761 3197,
760762 /**/
761763 3196,
Show on old repository browser