mirror of
https://github.com/neovim/neovim.git
synced 2025-09-07 11:58:17 +00:00
vim-patch:9.1.0097: 'breakindent' behaves inconsistently with 'list' and splits (#27432)
Problem: 'breakindent' behaves inconsistently with 'list' and splits.
Solution: Use 'listchars' from the correct window and handle caching
properly. Move cheaper comparisons to the top.
(zeertzjq)
closes: vim/vim#14008
efabd7c8d4
This commit is contained in:
@@ -806,51 +806,63 @@ int get_breakindent_win(win_T *wp, char *line)
|
|||||||
{
|
{
|
||||||
static int prev_indent = 0; // cached indent value
|
static int prev_indent = 0; // cached indent value
|
||||||
static OptInt prev_ts = 0; // cached tabstop value
|
static OptInt prev_ts = 0; // cached tabstop value
|
||||||
|
static colnr_T *prev_vts = NULL; // cached vartabs values
|
||||||
static int prev_fnum = 0; // cached buffer number
|
static int prev_fnum = 0; // cached buffer number
|
||||||
static char *prev_line = NULL; // cached copy of "line"
|
static char *prev_line = NULL; // cached copy of "line"
|
||||||
static varnumber_T prev_tick = 0; // changedtick of cached value
|
static varnumber_T prev_tick = 0; // changedtick of cached value
|
||||||
static colnr_T *prev_vts = NULL; // cached vartabs values
|
static int prev_list = 0; // cached list indent
|
||||||
static int prev_list = 0; // cached list value
|
|
||||||
static int prev_listopt = 0; // cached w_p_briopt_list value
|
static int prev_listopt = 0; // cached w_p_briopt_list value
|
||||||
|
static bool prev_no_ts = false; // cached no_ts value
|
||||||
|
static unsigned prev_dy_uhex = 0; // cached 'display' "uhex" value
|
||||||
static char *prev_flp = NULL; // cached formatlistpat value
|
static char *prev_flp = NULL; // cached formatlistpat value
|
||||||
int bri = 0;
|
int bri = 0;
|
||||||
// window width minus window margin space, i.e. what rests for text
|
// window width minus window margin space, i.e. what rests for text
|
||||||
const int eff_wwidth = wp->w_width_inner -
|
const int eff_wwidth = wp->w_width_inner -
|
||||||
((wp->w_p_nu || wp->w_p_rnu)
|
((wp->w_p_nu || wp->w_p_rnu)
|
||||||
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL) ? number_width(wp) + 1 : 0);
|
&& (vim_strchr(p_cpo, CPO_NUMCOL) == NULL)
|
||||||
|
? number_width(wp) + 1 : 0);
|
||||||
|
|
||||||
// used cached indent, unless
|
// In list mode, if 'listchars' "tab" isn't set, a TAB is displayed as ^I.
|
||||||
// - buffer changed
|
const bool no_ts = wp->w_p_list && wp->w_p_lcs_chars.tab1 == NUL;
|
||||||
// - 'tabstop' changed
|
|
||||||
// - buffer was changed
|
// Used cached indent, unless
|
||||||
// - 'briopt_list changed' changed or
|
// - buffer changed, or
|
||||||
// - 'formatlistpattern' changed
|
// - 'tabstop' changed, or
|
||||||
// - line changed
|
// - 'vartabstop' changed, or
|
||||||
// - 'vartabs' changed
|
// - buffer was changed, or
|
||||||
|
// - 'breakindentopt' "list" changed, or
|
||||||
|
// - 'list' or 'listchars' "tab" changed, or
|
||||||
|
// - 'display' "uhex" flag changed, or
|
||||||
|
// - 'formatlistpat' changed, or
|
||||||
|
// - line changed.
|
||||||
if (prev_fnum != wp->w_buffer->b_fnum
|
if (prev_fnum != wp->w_buffer->b_fnum
|
||||||
|| prev_ts != wp->w_buffer->b_p_ts
|
|| prev_ts != wp->w_buffer->b_p_ts
|
||||||
|
|| prev_vts != wp->w_buffer->b_p_vts_array
|
||||||
|| prev_tick != buf_get_changedtick(wp->w_buffer)
|
|| prev_tick != buf_get_changedtick(wp->w_buffer)
|
||||||
|| prev_listopt != wp->w_briopt_list
|
|| prev_listopt != wp->w_briopt_list
|
||||||
|
|| prev_no_ts != no_ts
|
||||||
|
|| prev_dy_uhex != (dy_flags & DY_UHEX)
|
||||||
|| prev_flp == NULL
|
|| prev_flp == NULL
|
||||||
|| strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0
|
|| strcmp(prev_flp, get_flp_value(wp->w_buffer)) != 0
|
||||||
|| prev_line == NULL || strcmp(prev_line, line) != 0
|
|| prev_line == NULL || strcmp(prev_line, line) != 0) {
|
||||||
|| prev_vts != wp->w_buffer->b_p_vts_array) {
|
|
||||||
prev_fnum = wp->w_buffer->b_fnum;
|
prev_fnum = wp->w_buffer->b_fnum;
|
||||||
xfree(prev_line);
|
xfree(prev_line);
|
||||||
prev_line = xstrdup(line);
|
prev_line = xstrdup(line);
|
||||||
prev_ts = wp->w_buffer->b_p_ts;
|
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_vts = wp->w_buffer->b_p_vts_array;
|
||||||
if (wp->w_briopt_vcol == 0) {
|
if (wp->w_briopt_vcol == 0) {
|
||||||
if (wp->w_p_list && !wp->w_p_lcs_chars.tab1) {
|
if (no_ts) {
|
||||||
prev_indent = indent_size_no_ts(line);
|
prev_indent = indent_size_no_ts(line);
|
||||||
} else {
|
} else {
|
||||||
prev_indent = indent_size_ts(line, wp->w_buffer->b_p_ts,
|
prev_indent = indent_size_ts(line, wp->w_buffer->b_p_ts,
|
||||||
wp->w_buffer->b_p_vts_array);
|
wp->w_buffer->b_p_vts_array);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
prev_tick = buf_get_changedtick(wp->w_buffer);
|
||||||
prev_listopt = wp->w_briopt_list;
|
prev_listopt = wp->w_briopt_list;
|
||||||
prev_list = 0;
|
prev_list = 0;
|
||||||
|
prev_no_ts = no_ts;
|
||||||
|
prev_dy_uhex = (dy_flags & DY_UHEX);
|
||||||
xfree(prev_flp);
|
xfree(prev_flp);
|
||||||
prev_flp = xstrdup(get_flp_value(wp->w_buffer));
|
prev_flp = xstrdup(get_flp_value(wp->w_buffer));
|
||||||
// add additional indent for numbered lists
|
// add additional indent for numbered lists
|
||||||
|
@@ -450,7 +450,7 @@ func Test_breakindent12()
|
|||||||
\ "~ ",
|
\ "~ ",
|
||||||
\ ]
|
\ ]
|
||||||
call s:compare_lines(expect, lines)
|
call s:compare_lines(expect, lines)
|
||||||
call s:close_windows('set nuw=4 listchars=')
|
call s:close_windows('set nuw=4 listchars&')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_breakindent12_vartabs()
|
func Test_breakindent12_vartabs()
|
||||||
@@ -467,7 +467,7 @@ func Test_breakindent12_vartabs()
|
|||||||
\ "~ ",
|
\ "~ ",
|
||||||
\ ]
|
\ ]
|
||||||
call s:compare_lines(expect, lines)
|
call s:compare_lines(expect, lines)
|
||||||
call s:close_windows('set nuw=4 listchars= vts&')
|
call s:close_windows('set nuw=4 listchars& vts&')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func Test_breakindent13()
|
func Test_breakindent13()
|
||||||
@@ -1126,5 +1126,51 @@ func Test_linebreak_list()
|
|||||||
bwipe!
|
bwipe!
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
func Test_breakindent_change_display_uhex()
|
||||||
|
call s:test_windows('setl briopt=min:0 list listchars=eol:$')
|
||||||
|
redraw!
|
||||||
|
let lines = s:screen_lines(line('.'), 20)
|
||||||
|
let expect = [
|
||||||
|
\ "^Iabcdefghijklmnopqr",
|
||||||
|
\ " stuvwxyzABCDEFGHIJ",
|
||||||
|
\ " KLMNOP$ "
|
||||||
|
\ ]
|
||||||
|
call s:compare_lines(expect, lines)
|
||||||
|
set display+=uhex
|
||||||
|
redraw!
|
||||||
|
let lines = s:screen_lines(line('.'), 20)
|
||||||
|
let expect = [
|
||||||
|
\ "<09>abcdefghijklmnop",
|
||||||
|
\ " qrstuvwxyzABCDEF",
|
||||||
|
\ " GHIJKLMNOP$ "
|
||||||
|
\ ]
|
||||||
|
call s:compare_lines(expect, lines)
|
||||||
|
set display&
|
||||||
|
|
||||||
|
call s:close_windows()
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_breakindent_list_split()
|
||||||
|
10new
|
||||||
|
61vsplit
|
||||||
|
setlocal tabstop=8 breakindent list listchars=tab:<->,eol:$
|
||||||
|
put =s:input
|
||||||
|
30vsplit
|
||||||
|
setlocal listchars=eol:$
|
||||||
|
let expect = [
|
||||||
|
\ "^IabcdefghijklmnopqrstuvwxyzAB|<------>abcdefghijklmnopqrstuv",
|
||||||
|
\ " CDEFGHIJKLMNOP$ | wxyzABCDEFGHIJKLMNOP$ ",
|
||||||
|
\ "~ |~ "
|
||||||
|
\ ]
|
||||||
|
redraw!
|
||||||
|
let lines = s:screen_lines(line('.'), 61)
|
||||||
|
call s:compare_lines(expect, lines)
|
||||||
|
wincmd p
|
||||||
|
redraw!
|
||||||
|
let lines = s:screen_lines(line('.'), 61)
|
||||||
|
call s:compare_lines(expect, lines)
|
||||||
|
|
||||||
|
bwipe!
|
||||||
|
endfunc
|
||||||
|
|
||||||
" vim: shiftwidth=2 sts=2 expandtab
|
" vim: shiftwidth=2 sts=2 expandtab
|
||||||
|
Reference in New Issue
Block a user