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)

e7d6dbc572

Co-authored-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
zeertzjq 2022-11-05 19:19:55 +08:00
parent 6374120558
commit e0ec83a970
4 changed files with 88 additions and 13 deletions

View File

@ -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")

View File

@ -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))

View File

@ -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);

View File

@ -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