aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2022-11-05 19:19:55 +0800
committerzeertzjq <zeertzjq@outlook.com>2022-11-05 19:35:56 +0800
commite0ec83a9701ffd9b30a41763ad2e2326d85d8480 (patch)
treeab9303393cb6190fb82e93893620e8ed56bed052
parent6374120558476b9ab0ec4dc1df0523c73756e4ae (diff)
downloadrneovim-e0ec83a9701ffd9b30a41763ad2e2326d85d8480.tar.gz
rneovim-e0ec83a9701ffd9b30a41763ad2e2326d85d8480.tar.bz2
rneovim-e0ec83a9701ffd9b30a41763ad2e2326d85d8480.zip
vim-patch:8.2.4882: cannot make 'breakindent' use a specific column
Problem: Cannot make 'breakindent' use a specific column. Solution: Add the "column" entry in 'breakindentopt'. (Christian Brabandt, closes vim/vim#10362, closes vim/vim#10325) https://github.com/vim/vim/commit/e7d6dbc5721342e3d6b04cf285e4510b5569e707 Co-authored-by: Christian Brabandt <cb@256bit.org>
-rw-r--r--runtime/doc/options.txt8
-rw-r--r--src/nvim/buffer_defs.h4
-rw-r--r--src/nvim/indent.c27
-rw-r--r--src/nvim/testdir/test_breakindent.vim62
4 files changed, 88 insertions, 13 deletions
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index d14bb275d2..818c6d0115 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -1059,14 +1059,20 @@ A jump table for the options with a short description can be found at |Q_op|.
characters. It permits dynamic French paragraph
indentation (negative) or emphasizing the line
continuation (positive).
+ (default: 0)
sbr Display the 'showbreak' value before applying the
additional indent.
+ (default: off)
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.
+ (default: 0)
+ column:{n} Indent at column {n}. Will overrule the other
+ sub-options. Note: an additional indent may be
+ added for the 'showbreak' setting.
+ (default: off)
*'browsedir'* *'bsdir'*
'browsedir' 'bsdir' string (default: "last")
diff --git a/src/nvim/buffer_defs.h b/src/nvim/buffer_defs.h
index 3629199f9a..4e46a1aef2 100644
--- a/src/nvim/buffer_defs.h
+++ b/src/nvim/buffer_defs.h
@@ -963,7 +963,8 @@ struct frame_S {
// for first
// fr_child and fr_win are mutually exclusive
frame_T *fr_child; // first contained frame
- win_T *fr_win; // window that fills this frame
+ win_T *fr_win; // window that fills this frame; for a snapshot
+ // set to the current window
};
#define FR_LEAF 0 // frame is a leaf
@@ -1340,6 +1341,7 @@ struct window_S {
int w_briopt_shift; // additional shift for breakindent
bool w_briopt_sbr; // sbr in 'briopt'
int w_briopt_list; // additional indent for lists
+ int w_briopt_vcol; // indent for specific column
// transform a pointer to a "onebuf" option into a "allbuf" option
#define GLOBAL_WO(p) ((char *)(p) + sizeof(winopt_T))
diff --git a/src/nvim/indent.c b/src/nvim/indent.c
index 359dd32fdf..d372e41459 100644
--- a/src/nvim/indent.c
+++ b/src/nvim/indent.c
@@ -743,6 +743,7 @@ bool briopt_check(win_T *wp)
int bri_min = 20;
bool bri_sbr = false;
int bri_list = 0;
+ int bri_vcol = 0;
char *p = wp->w_p_briopt;
while (*p != NUL) {
@@ -759,6 +760,9 @@ bool briopt_check(win_T *wp)
} else if (STRNCMP(p, "list:", 5) == 0) {
p += 5;
bri_list = (int)getdigits(&p, false, 0);
+ } else if (STRNCMP(p, "column:", 7) == 0) {
+ p += 7;
+ bri_vcol = (int)getdigits(&p, false, 0);
}
if (*p != ',' && *p != NUL) {
return false;
@@ -771,7 +775,8 @@ bool briopt_check(win_T *wp)
wp->w_briopt_shift = bri_shift;
wp->w_briopt_min = bri_min;
wp->w_briopt_sbr = bri_sbr;
- wp->w_briopt_list = bri_list;
+ wp->w_briopt_list = bri_list;
+ wp->w_briopt_vcol = bri_vcol;
return true;
}
@@ -810,16 +815,18 @@ int get_breakindent_win(win_T *wp, char_u *line)
prev_ts = wp->w_buffer->b_p_ts;
prev_tick = buf_get_changedtick(wp->w_buffer);
prev_vts = wp->w_buffer->b_p_vts_array;
- prev_indent = get_indent_str_vtab((char *)line,
- wp->w_buffer->b_p_ts,
- wp->w_buffer->b_p_vts_array,
- wp->w_p_list);
+ if (wp->w_briopt_vcol == 0) {
+ prev_indent = get_indent_str_vtab((char *)line,
+ wp->w_buffer->b_p_ts,
+ wp->w_buffer->b_p_vts_array,
+ wp->w_p_list);
+ }
prev_listopt = wp->w_briopt_list;
prev_list = 0;
xfree(prev_flp);
prev_flp = xstrdup(get_flp_value(wp->w_buffer));
// add additional indent for numbered lists
- if (wp->w_briopt_list != 0) {
+ if (wp->w_briopt_list != 0 && wp->w_briopt_vcol == 0) {
regmatch_T regmatch = {
.regprog = vim_regcomp(prev_flp, RE_MAGIC + RE_STRING + RE_AUTO + RE_STRICT),
};
@@ -836,7 +843,13 @@ int get_breakindent_win(win_T *wp, char_u *line)
}
}
}
- bri = prev_indent + wp->w_briopt_shift;
+ if (wp->w_briopt_vcol != 0) {
+ // column value has priority
+ bri = wp->w_briopt_vcol;
+ prev_list = 0;
+ } else {
+ bri = prev_indent + wp->w_briopt_shift;
+ }
// Add offset for number column, if 'n' is in 'cpoptions'
bri += win_col_off2(wp);
diff --git a/src/nvim/testdir/test_breakindent.vim b/src/nvim/testdir/test_breakindent.vim
index 934dca4793..995683c68c 100644
--- a/src/nvim/testdir/test_breakindent.vim
+++ b/src/nvim/testdir/test_breakindent.vim
@@ -877,16 +877,17 @@ endfunc
func Test_window_resize_with_linebreak()
new
53vnew
- set linebreak
- set showbreak=>>
- set breakindent
- set breakindentopt=shift:4
+ setl linebreak
+ setl showbreak=>>
+ setl breakindent
+ setl breakindentopt=shift:4
call setline(1, "\naaaaaaaaa\n\na\naaaaa\n¯aaaaaaaaaa\naaaaaaaaaaaa\naaa\n\"a:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - aaaaaaaa\"\naaaaaaaa\n\"a")
redraw!
call assert_equal([" >>aa^@\"a: "], ScreenLines(2, 14))
vertical resize 52
redraw!
call assert_equal([" >>aaa^@\"a:"], ScreenLines(2, 14))
+ set linebreak& showbreak& breakindent& breakindentopt&
%bw!
endfunc
@@ -983,4 +984,57 @@ func Test_no_extra_indent()
bwipeout!
endfunc
+func Test_breakindent_column()
+ " restore original
+ let s:input ="\tabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOP"
+ call s:test_windows('setl breakindent breakindentopt=column:10')
+ redraw!
+ " 1) default: does not indent, too wide :(
+ let expect = [
+ \ " ",
+ \ " abcdefghijklmnop",
+ \ "qrstuvwxyzABCDEFGHIJ",
+ \ "KLMNOP "
+ \ ]
+ let lines = s:screen_lines2(1, 4, 20)
+ call s:compare_lines(expect, lines)
+ " 2) lower min value, so that breakindent works
+ setl breakindentopt+=min:5
+ redraw!
+ let expect = [
+ \ " ",
+ \ " abcdefghijklmnop",
+ \ " qrstuvwxyz",
+ \ " ABCDEFGHIJ",
+ \ " KLMNOP "
+ \ ]
+ let lines = s:screen_lines2(1, 5, 20)
+ " 3) set shift option -> no influence
+ setl breakindentopt+=shift:5
+ redraw!
+ let expect = [
+ \ " ",
+ \ " abcdefghijklmnop",
+ \ " qrstuvwxyz",
+ \ " ABCDEFGHIJ",
+ \ " KLMNOP "
+ \ ]
+ let lines = s:screen_lines2(1, 5, 20)
+ call s:compare_lines(expect, lines)
+ " 4) add showbreak value
+ setl showbreak=++
+ redraw!
+ let expect = [
+ \ " ",
+ \ " abcdefghijklmnop",
+ \ " ++qrstuvwx",
+ \ " ++yzABCDEF",
+ \ " ++GHIJKLMN",
+ \ " ++OP "
+ \ ]
+ let lines = s:screen_lines2(1, 6, 20)
+ call s:compare_lines(expect, lines)
+ bwipeout!
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab