aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--runtime/doc/options.txt4
-rw-r--r--src/nvim/indent.c16
-rw-r--r--src/nvim/option.c6
-rw-r--r--src/nvim/testdir/test_breakindent.vim55
4 files changed, 73 insertions, 8 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 04cb7141df..f0ce15ac0f 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1038,9 +1038,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'*
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 4e734421a4..bfb77688b0 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -462,15 +462,11 @@ int get_breakindent_win(win_T *wp, char_u *line)
}
bri = prev_indent + wp->w_briopt_shift;
- // indent minus the length of the showbreak string
- if (wp->w_briopt_sbr) {
- bri -= vim_strsize(p_sbr);
- }
// 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 = {
.regprog = vim_regcomp(curbuf->b_p_flp,
RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT),
@@ -478,12 +474,20 @@ int get_breakindent_win(win_T *wp, char_u *line)
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 = (int)(*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) {
diff --git a/src/nvim/option.c b/src/nvim/option.c
index e1f3e143ed..0595776f79 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -7674,6 +7674,12 @@ int win_signcol_configured(win_T *wp, int *is_fixed)
return ret;
}
+// Get the local or global value of 'showbreak'.
+char_u *get_showbreak_value(win_T *win FUNC_ATTR_UNUSED)
+{
+ return p_sbr;
+}
+
/// Get window or buffer local options
dict_T *get_winbuf_options(const int bufopt)
FUNC_ATTR_WARN_UNUSED_RESULT
diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim
index dbaa4c44a0..5542746a04 100644
--- a/src/nvim/testdir/test_breakindent.vim
+++ b/src/nvim/testdir/test_breakindent.vim
@@ -796,6 +796,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.
@@ -812,7 +813,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