forked from aniani/vim
patch 9.0.0533: the win_line() function is much too long
Problem: The win_line() function is much too long. Solution: Move code to separate functions.
This commit is contained in:
189
src/drawline.c
189
src/drawline.c
@@ -103,6 +103,9 @@ typedef struct {
|
|||||||
int win_attr; // background for the whole window, except
|
int win_attr; // background for the whole window, except
|
||||||
// margins and "~" lines.
|
// margins and "~" lines.
|
||||||
int wcr_attr; // attributes from 'wincolor'
|
int wcr_attr; // attributes from 'wincolor'
|
||||||
|
#ifdef FEAT_SYN_HL
|
||||||
|
int cul_attr; // set when 'cursorline' active
|
||||||
|
#endif
|
||||||
|
|
||||||
int screen_line_flags; // flags for screen_line()
|
int screen_line_flags; // flags for screen_line()
|
||||||
|
|
||||||
@@ -110,6 +113,7 @@ typedef struct {
|
|||||||
int tocol; // end of inverting
|
int tocol; // end of inverting
|
||||||
|
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
|
long vcol_sbr; // virtual column after showbreak
|
||||||
int need_showbreak; // overlong line, skipping first x chars
|
int need_showbreak; // overlong line, skipping first x chars
|
||||||
int dont_use_showbreak; // do not use 'showbreak'
|
int dont_use_showbreak; // do not use 'showbreak'
|
||||||
#endif
|
#endif
|
||||||
@@ -122,11 +126,10 @@ typedef struct {
|
|||||||
int n_extra; // number of extra bytes
|
int n_extra; // number of extra bytes
|
||||||
char_u *p_extra; // string of extra chars, plus NUL, only used
|
char_u *p_extra; // string of extra chars, plus NUL, only used
|
||||||
// when c_extra and c_final are NUL
|
// when c_extra and c_final are NUL
|
||||||
|
char_u *p_extra_free; // p_extra buffer that needs to be freed
|
||||||
int c_extra; // extra chars, all the same
|
int c_extra; // extra chars, all the same
|
||||||
int c_final; // final char, mandatory if set
|
int c_final; // final char, mandatory if set
|
||||||
|
|
||||||
char_u *p_extra_free; // p_extra buffer that needs to be freed
|
|
||||||
|
|
||||||
// saved "extra" items for when draw_state becomes WL_LINE (again)
|
// saved "extra" items for when draw_state becomes WL_LINE (again)
|
||||||
int saved_n_extra;
|
int saved_n_extra;
|
||||||
char_u *saved_p_extra;
|
char_u *saved_p_extra;
|
||||||
@@ -491,6 +494,62 @@ handle_breakindent(win_T *wp, winlinevars_T *wlv)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
|
||||||
|
static void
|
||||||
|
handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
|
||||||
|
{
|
||||||
|
# ifdef FEAT_DIFF
|
||||||
|
if (wlv->filler_todo > 0)
|
||||||
|
{
|
||||||
|
// Draw "deleted" diff line(s).
|
||||||
|
if (char2cells(wp->w_fill_chars.diff) > 1)
|
||||||
|
{
|
||||||
|
wlv->c_extra = '-';
|
||||||
|
wlv->c_final = NUL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wlv->c_extra = wp->w_fill_chars.diff;
|
||||||
|
wlv->c_final = NUL;
|
||||||
|
}
|
||||||
|
# ifdef FEAT_RIGHTLEFT
|
||||||
|
if (wp->w_p_rl)
|
||||||
|
wlv->n_extra = wlv->col + 1;
|
||||||
|
else
|
||||||
|
# endif
|
||||||
|
wlv->n_extra = wp->w_width - wlv->col;
|
||||||
|
wlv->char_attr = HL_ATTR(HLF_DED);
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
|
# ifdef FEAT_LINEBREAK
|
||||||
|
char_u *sbr = get_showbreak_value(wp);
|
||||||
|
if (*sbr != NUL && wlv->need_showbreak)
|
||||||
|
{
|
||||||
|
// Draw 'showbreak' at the start of each broken line.
|
||||||
|
wlv->p_extra = sbr;
|
||||||
|
wlv->c_extra = NUL;
|
||||||
|
wlv->c_final = NUL;
|
||||||
|
wlv->n_extra = (int)STRLEN(sbr);
|
||||||
|
if (wp->w_skipcol == 0 || !wp->w_p_wrap)
|
||||||
|
wlv->need_showbreak = FALSE;
|
||||||
|
wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
|
||||||
|
// Correct end of highlighted area for 'showbreak',
|
||||||
|
// required when 'linebreak' is also set.
|
||||||
|
if (wlv->tocol == wlv->vcol)
|
||||||
|
wlv->tocol += wlv->n_extra;
|
||||||
|
// combine 'showbreak' with 'wincolor'
|
||||||
|
wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
|
||||||
|
# ifdef FEAT_SYN_HL
|
||||||
|
// combine 'showbreak' with 'cursorline'
|
||||||
|
if (wlv->cul_attr != 0)
|
||||||
|
wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(FEAT_PROP_POPUP) || defined(PROTO)
|
#if defined(FEAT_PROP_POPUP) || defined(PROTO)
|
||||||
/*
|
/*
|
||||||
* Return the cell size of virtual text after truncation.
|
* Return the cell size of virtual text after truncation.
|
||||||
@@ -801,6 +860,25 @@ win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Called when wlv->draw_state is set to WL_LINE.
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
win_line_continue(winlinevars_T *wlv)
|
||||||
|
{
|
||||||
|
if (wlv->saved_n_extra > 0)
|
||||||
|
{
|
||||||
|
// Continue item from end of wrapped line.
|
||||||
|
wlv->n_extra = wlv->saved_n_extra;
|
||||||
|
wlv->c_extra = wlv->saved_c_extra;
|
||||||
|
wlv->c_final = wlv->saved_c_final;
|
||||||
|
wlv->p_extra = wlv->saved_p_extra;
|
||||||
|
wlv->char_attr = wlv->saved_char_attr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
wlv->char_attr = wlv->win_attr;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Display line "lnum" of window 'wp' on the screen.
|
* Display line "lnum" of window 'wp' on the screen.
|
||||||
* Start at row "startrow", stop when "endrow" is reached.
|
* Start at row "startrow", stop when "endrow" is reached.
|
||||||
@@ -820,9 +898,6 @@ win_line(
|
|||||||
winlinevars_T wlv; // variables passed between functions
|
winlinevars_T wlv; // variables passed between functions
|
||||||
|
|
||||||
int c = 0; // init for GCC
|
int c = 0; // init for GCC
|
||||||
#ifdef FEAT_LINEBREAK
|
|
||||||
long vcol_sbr = -1; // virtual column after showbreak
|
|
||||||
#endif
|
|
||||||
long vcol_prev = -1; // "wlv.vcol" of previous character
|
long vcol_prev = -1; // "wlv.vcol" of previous character
|
||||||
char_u *line; // current line
|
char_u *line; // current line
|
||||||
char_u *ptr; // current position in "line"
|
char_u *ptr; // current position in "line"
|
||||||
@@ -937,9 +1012,8 @@ win_line(
|
|||||||
#ifdef FEAT_TERMINAL
|
#ifdef FEAT_TERMINAL
|
||||||
int get_term_attr = FALSE;
|
int get_term_attr = FALSE;
|
||||||
#endif
|
#endif
|
||||||
#ifdef FEAT_SYN_HL
|
|
||||||
int cul_attr = 0; // set when 'cursorline' active
|
|
||||||
|
|
||||||
|
#ifdef FEAT_SYN_HL
|
||||||
// margin columns for the screen line, needed for when 'cursorlineopt'
|
// margin columns for the screen line, needed for when 'cursorlineopt'
|
||||||
// contains "screenline"
|
// contains "screenline"
|
||||||
int left_curline_col = 0;
|
int left_curline_col = 0;
|
||||||
@@ -988,6 +1062,9 @@ win_line(
|
|||||||
wlv.screen_row = wlv.row + W_WINROW(wp);
|
wlv.screen_row = wlv.row + W_WINROW(wp);
|
||||||
wlv.fromcol = -10;
|
wlv.fromcol = -10;
|
||||||
wlv.tocol = MAXCOL;
|
wlv.tocol = MAXCOL;
|
||||||
|
#ifdef FEAT_LINEBREAK
|
||||||
|
wlv.vcol_sbr = -1;
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!number_only)
|
if (!number_only)
|
||||||
{
|
{
|
||||||
@@ -1481,16 +1558,16 @@ win_line(
|
|||||||
// 'cursorlineopt'. Otherwise it's done later.
|
// 'cursorlineopt'. Otherwise it's done later.
|
||||||
if (!wlv.cul_screenline)
|
if (!wlv.cul_screenline)
|
||||||
{
|
{
|
||||||
cul_attr = HL_ATTR(HLF_CUL);
|
wlv.cul_attr = HL_ATTR(HLF_CUL);
|
||||||
# ifdef FEAT_SIGNS
|
# ifdef FEAT_SIGNS
|
||||||
// Combine the 'cursorline' and sign highlighting, depending on
|
// Combine the 'cursorline' and sign highlighting, depending on
|
||||||
// the sign priority.
|
// the sign priority.
|
||||||
if (sign_present && wlv.sattr.sat_linehl > 0)
|
if (sign_present && wlv.sattr.sat_linehl > 0)
|
||||||
{
|
{
|
||||||
if (wlv.sattr.sat_priority >= 100)
|
if (wlv.sattr.sat_priority >= 100)
|
||||||
line_attr = hl_combine_attr(cul_attr, line_attr);
|
line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
|
||||||
else
|
else
|
||||||
line_attr = hl_combine_attr(line_attr, cul_attr);
|
line_attr = hl_combine_attr(line_attr, wlv.cul_attr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# endif
|
# endif
|
||||||
@@ -1498,9 +1575,9 @@ win_line(
|
|||||||
// let the line attribute overrule 'cursorline', otherwise
|
// let the line attribute overrule 'cursorline', otherwise
|
||||||
// it disappears when both have background set;
|
// it disappears when both have background set;
|
||||||
// 'cursorline' can use underline or bold to make it show
|
// 'cursorline' can use underline or bold to make it show
|
||||||
line_attr = hl_combine_attr(cul_attr, line_attr);
|
line_attr = hl_combine_attr(wlv.cul_attr, line_attr);
|
||||||
# else
|
# else
|
||||||
line_attr = cul_attr;
|
line_attr = wlv.cul_attr;
|
||||||
# endif
|
# endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1558,11 +1635,10 @@ win_line(
|
|||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
if (wlv.cul_screenline)
|
if (wlv.cul_screenline)
|
||||||
{
|
{
|
||||||
cul_attr = 0;
|
wlv.cul_attr = 0;
|
||||||
line_attr = line_attr_save;
|
line_attr = line_attr_save;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_CMDWIN
|
#ifdef FEAT_CMDWIN
|
||||||
if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
@@ -1578,7 +1654,6 @@ win_line(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
@@ -1586,7 +1661,6 @@ win_line(
|
|||||||
handle_foldcolumn(wp, &wlv);
|
handle_foldcolumn(wp, &wlv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef FEAT_SIGNS
|
#ifdef FEAT_SIGNS
|
||||||
if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
@@ -1596,103 +1670,39 @@ win_line(
|
|||||||
get_sign_display_info(FALSE, wp, &wlv);
|
get_sign_display_info(FALSE, wp, &wlv);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
// Show the line number, if desired.
|
// Show the line number, if desired.
|
||||||
wlv.draw_state = WL_NR;
|
wlv.draw_state = WL_NR;
|
||||||
handle_lnum_col(wp, &wlv, sign_present, num_attr);
|
handle_lnum_col(wp, &wlv, sign_present, num_attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_LINEBREAK
|
#ifdef FEAT_LINEBREAK
|
||||||
// Check if 'breakindent' applies and show it.
|
// Check if 'breakindent' applies and show it.
|
||||||
// May change wlv.draw_state to WL_BRI or WL_BRI - 1.
|
// May change wlv.draw_state to WL_BRI or WL_BRI - 1.
|
||||||
if (wlv.n_extra == 0)
|
if (wlv.n_extra == 0)
|
||||||
handle_breakindent(wp, &wlv);
|
handle_breakindent(wp, &wlv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
|
#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
|
||||||
if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
char_u *sbr;
|
|
||||||
|
|
||||||
wlv.draw_state = WL_SBR;
|
wlv.draw_state = WL_SBR;
|
||||||
# ifdef FEAT_DIFF
|
handle_showbreak_and_filler(wp, &wlv);
|
||||||
if (wlv.filler_todo > 0)
|
|
||||||
{
|
|
||||||
// Draw "deleted" diff line(s).
|
|
||||||
if (char2cells(wp->w_fill_chars.diff) > 1)
|
|
||||||
{
|
|
||||||
wlv.c_extra = '-';
|
|
||||||
wlv.c_final = NUL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wlv.c_extra = wp->w_fill_chars.diff;
|
|
||||||
wlv.c_final = NUL;
|
|
||||||
}
|
|
||||||
# ifdef FEAT_RIGHTLEFT
|
|
||||||
if (wp->w_p_rl)
|
|
||||||
wlv.n_extra = wlv.col + 1;
|
|
||||||
else
|
|
||||||
# endif
|
|
||||||
wlv.n_extra = wp->w_width - wlv.col;
|
|
||||||
wlv.char_attr = HL_ATTR(HLF_DED);
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
# ifdef FEAT_LINEBREAK
|
|
||||||
sbr = get_showbreak_value(wp);
|
|
||||||
if (*sbr != NUL && wlv.need_showbreak)
|
|
||||||
{
|
|
||||||
// Draw 'showbreak' at the start of each broken line.
|
|
||||||
wlv.p_extra = sbr;
|
|
||||||
wlv.c_extra = NUL;
|
|
||||||
wlv.c_final = NUL;
|
|
||||||
wlv.n_extra = (int)STRLEN(sbr);
|
|
||||||
if (wp->w_skipcol == 0 || !wp->w_p_wrap)
|
|
||||||
wlv.need_showbreak = FALSE;
|
|
||||||
vcol_sbr = wlv.vcol + MB_CHARLEN(sbr);
|
|
||||||
// Correct end of highlighted area for 'showbreak',
|
|
||||||
// required when 'linebreak' is also set.
|
|
||||||
if (wlv.tocol == wlv.vcol)
|
|
||||||
wlv.tocol += wlv.n_extra;
|
|
||||||
// combine 'showbreak' with 'wincolor'
|
|
||||||
wlv.char_attr = hl_combine_attr(wlv.win_attr,
|
|
||||||
HL_ATTR(HLF_AT));
|
|
||||||
# ifdef FEAT_SYN_HL
|
|
||||||
// combine 'showbreak' with 'cursorline'
|
|
||||||
if (cul_attr != 0)
|
|
||||||
wlv.char_attr = hl_combine_attr(wlv.char_attr,
|
|
||||||
cul_attr);
|
|
||||||
# endif
|
|
||||||
}
|
|
||||||
# endif
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
|
if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
|
||||||
{
|
{
|
||||||
wlv.draw_state = WL_LINE;
|
wlv.draw_state = WL_LINE;
|
||||||
if (wlv.saved_n_extra)
|
win_line_continue(&wlv); // use wlv.saved_ values
|
||||||
{
|
|
||||||
// Continue item from end of wrapped line.
|
|
||||||
wlv.n_extra = wlv.saved_n_extra;
|
|
||||||
wlv.c_extra = wlv.saved_c_extra;
|
|
||||||
wlv.c_final = wlv.saved_c_final;
|
|
||||||
wlv.p_extra = wlv.saved_p_extra;
|
|
||||||
wlv.char_attr = wlv.saved_char_attr;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
wlv.char_attr = wlv.win_attr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
if (wlv.cul_screenline && wlv.draw_state == WL_LINE
|
if (wlv.cul_screenline && wlv.draw_state == WL_LINE
|
||||||
&& wlv.vcol >= left_curline_col
|
&& wlv.vcol >= left_curline_col
|
||||||
&& wlv.vcol < right_curline_col)
|
&& wlv.vcol < right_curline_col)
|
||||||
{
|
{
|
||||||
cul_attr = HL_ATTR(HLF_CUL);
|
wlv.cul_attr = HL_ATTR(HLF_CUL);
|
||||||
line_attr = cul_attr;
|
line_attr = wlv.cul_attr;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -2226,8 +2236,9 @@ win_line(
|
|||||||
mb_utf8 = FALSE;
|
mb_utf8 = FALSE;
|
||||||
multi_attr = HL_ATTR(HLF_AT);
|
multi_attr = HL_ATTR(HLF_AT);
|
||||||
#ifdef FEAT_SYN_HL
|
#ifdef FEAT_SYN_HL
|
||||||
if (cul_attr)
|
if (wlv.cul_attr)
|
||||||
multi_attr = hl_combine_attr(multi_attr, cul_attr);
|
multi_attr = hl_combine_attr(
|
||||||
|
multi_attr, wlv.cul_attr);
|
||||||
#endif
|
#endif
|
||||||
multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
|
multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
|
||||||
|
|
||||||
@@ -2565,7 +2576,7 @@ win_line(
|
|||||||
|
|
||||||
// We have just drawn the showbreak value, no need to add
|
// We have just drawn the showbreak value, no need to add
|
||||||
// space for it again.
|
// space for it again.
|
||||||
if (wlv.vcol == vcol_sbr)
|
if (wlv.vcol == wlv.vcol_sbr)
|
||||||
{
|
{
|
||||||
wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
|
wlv.n_extra -= MB_CHARLEN(get_showbreak_value(wp));
|
||||||
if (wlv.n_extra < 0)
|
if (wlv.n_extra < 0)
|
||||||
@@ -2710,7 +2721,7 @@ win_line(
|
|||||||
|
|
||||||
// only adjust the tab_len, when at the first column
|
// only adjust the tab_len, when at the first column
|
||||||
// after the showbreak value was drawn
|
// after the showbreak value was drawn
|
||||||
if (*sbr != NUL && wlv.vcol == vcol_sbr && wp->w_p_wrap)
|
if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
|
||||||
vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
|
vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
|
||||||
#endif
|
#endif
|
||||||
// tab amount depends on current column
|
// tab amount depends on current column
|
||||||
|
@@ -699,6 +699,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
533,
|
||||||
/**/
|
/**/
|
||||||
532,
|
532,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user