#include "vim.h"
#define MB_FILLER_CHAR '<'
static int screen_attr = 0;
static int screen_cur_row, screen_cur_col;
#ifdef FEAT_SEARCH_EXTRA
static match_T search_hl;
#endif
#if defined(FEAT_MENU) || defined(FEAT_FOLDING)
static int text_to_screenline(win_T *wp, char_u *text, int col);
#endif
#ifdef FEAT_FOLDING
static foldinfo_T win_foldinfo;
static int compute_foldcolumn(win_T *wp, int col);
#endif
static int redrawing_for_callback = 0;
static schar_T *current_ScreenLine;
static void win_update(win_T *wp);
static void win_draw_end(win_T *wp, int c1, int c2, int row, int endrow, hlf_T hl);
#ifdef FEAT_FOLDING
static void fold_line(win_T *wp, long fold_count, foldinfo_T *foldinfo, linenr_T lnum, int row);
static void fill_foldcolumn(char_u *p, win_T *wp, int closed, linenr_T lnum);
static void copy_text_attr(int off, char_u *buf, int len, int attr);
#endif
static int win_line(win_T *, linenr_T, int, int, int nochange);
static int char_needs_redraw(int off_from, int off_to, int cols);
static void draw_vsep_win(win_T *wp, int row);
#ifdef FEAT_STL_OPT
static void redraw_custom_statusline(win_T *wp);
#endif
#ifdef FEAT_SEARCH_EXTRA
# define SEARCH_HL_PRIORITY 0
static void start_search_hl(void);
static void end_search_hl(void);
static void init_search_hl(win_T *wp);
static void prepare_search_hl(win_T *wp, linenr_T lnum);
static void next_search_hl(win_T *win, match_T *shl, linenr_T lnum, colnr_T mincol, matchitem_T *cur);
static int next_search_hl_pos(match_T *shl, linenr_T lnum, posmatch_T *pos, colnr_T mincol);
#endif
static void screen_start_highlight(int attr);
static void screen_char(unsigned off, int row, int col);
#ifdef FEAT_MBYTE
static void screen_char_2(unsigned off, int row, int col);
#endif
static void screenclear2(void);
static void lineclear(unsigned off, int width, int attr);
static void lineinvalid(unsigned off, int width);
static void linecopy(int to, int from, win_T *wp);
static void redraw_block(int row, int end, win_T *wp);
static int win_do_lines(win_T *wp, int row, int line_count, int mayclear, int del, int clear_attr);
static void win_rest_invalid(win_T *wp);
static void msg_pos_mode(void);
static void recording_mode(int attr);
static void draw_tabline(void);
static int fillchar_status(int *attr, win_T *wp);
static int fillchar_vsep(int *attr);
#ifdef FEAT_MENU
static void redraw_win_toolbar(win_T *wp);
#endif
#ifdef FEAT_STL_OPT
static void win_redr_custom(win_T *wp, int draw_ruler);
#endif
#ifdef FEAT_CMDL_INFO
static void win_redr_ruler(win_T *wp, int always);
#endif
static int screen_char_attr = 0;
#if defined(FEAT_SYN_HL) && defined(FEAT_RELTIME)
# define SYN_TIME_LIMIT 1
#endif
#ifdef FEAT_RIGHTLEFT
# define HAS_RIGHTLEFT(x) x
#else
# define HAS_RIGHTLEFT(x) FALSE
#endif
void
redraw_later(int type)
{
redraw_win_later(curwin, type);
}
void
redraw_win_later(
win_T *wp,
int type)
{
if (!exiting && wp->w_redr_type < type)
{
wp->w_redr_type = type;
if (type >= NOT_VALID)
wp->w_lines_valid = 0;
if (must_redraw < type)
must_redraw = type;
}
}
void
redraw_later_clear(void)
{
redraw_all_later(CLEAR);
#ifdef FEAT_GUI
if (gui.in_use)
screen_attr = HL_ALL + 1;
else
#endif
screen_attr = HL_BOLD | HL_UNDERLINE | HL_INVERSE | HL_STRIKETHROUGH;
}
void
redraw_all_later(int type)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
{
redraw_win_later(wp, type);
}
}
void
redraw_curbuf_later(int type)
{
redraw_buf_later(curbuf, type);
}
void
redraw_buf_later(buf_T *buf, int type)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer == buf)
redraw_win_later(wp, type);
}
}
void
redraw_buf_and_status_later(buf_T *buf, int type)
{
win_T *wp;
#ifdef FEAT_WILDMENU
if (wild_menu_showing != 0)
return;
#endif
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer == buf)
{
redraw_win_later(wp, type);
wp->w_redr_status = TRUE;
}
}
}
int
redraw_asap(int type)
{
int rows;
int cols = screen_Columns;
int r;
int ret = 0;
schar_T *screenline;
sattr_T *screenattr;
#ifdef FEAT_MBYTE
int i;
u8char_T *screenlineUC = NULL;
u8char_T *screenlineC[MAX_MCO];
schar_T *screenline2 = NULL;
#endif
redraw_later(type);
if (msg_scrolled || (State != NORMAL && State != NORMAL_BUSY) || exiting)
return ret;
rows = screen_Rows - cmdline_row;
screenline = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
screenattr = (sattr_T *)lalloc(
(long_u)(rows * cols * sizeof(sattr_T)), FALSE);
if (screenline == NULL || screenattr == NULL)
ret = 2;
#ifdef FEAT_MBYTE
if (enc_utf8)
{
screenlineUC = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
if (screenlineUC == NULL)
ret = 2;
for (i = 0; i < p_mco; ++i)
{
screenlineC[i] = (u8char_T *)lalloc(
(long_u)(rows * cols * sizeof(u8char_T)), FALSE);
if (screenlineC[i] == NULL)
ret = 2;
}
}
if (enc_dbcs == DBCS_JPNU)
{
screenline2 = (schar_T *)lalloc(
(long_u)(rows * cols * sizeof(schar_T)), FALSE);
if (screenline2 == NULL)
ret = 2;
}
#endif
if (ret != 2)
{
for (r = 0; r < rows; ++r)
{
mch_memmove(screenline + r * cols,
ScreenLines + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(schar_T));
mch_memmove(screenattr + r * cols,
ScreenAttrs + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(sattr_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
mch_memmove(screenlineUC + r * cols,
ScreenLinesUC + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(screenlineC[i] + r * cols,
ScreenLinesC[i] + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
mch_memmove(screenline2 + r * cols,
ScreenLines2 + LineOffset[cmdline_row + r],
(size_t)cols * sizeof(schar_T));
#endif
}
update_screen(0);
ret = 3;
if (must_redraw == 0)
{
int off = (int)(current_ScreenLine - ScreenLines);
for (r = 0; r < rows; ++r)
{
mch_memmove(current_ScreenLine,
screenline + r * cols,
(size_t)cols * sizeof(schar_T));
mch_memmove(ScreenAttrs + off,
screenattr + r * cols,
(size_t)cols * sizeof(sattr_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
mch_memmove(ScreenLinesUC + off,
screenlineUC + r * cols,
(size_t)cols * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(ScreenLinesC[i] + off,
screenlineC[i] + r * cols,
(size_t)cols * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
mch_memmove(ScreenLines2 + off,
screenline2 + r * cols,
(size_t)cols * sizeof(schar_T));
#endif
screen_line(cmdline_row + r, 0, cols, cols, FALSE);
}
ret = 4;
}
}
vim_free(screenline);
vim_free(screenattr);
#ifdef FEAT_MBYTE
if (enc_utf8)
{
vim_free(screenlineUC);
for (i = 0; i < p_mco; ++i)
vim_free(screenlineC[i]);
}
if (enc_dbcs == DBCS_JPNU)
vim_free(screenline2);
#endif
maybe_intro_message();
setcursor();
return ret;
}
void
redraw_after_callback(int call_update_screen)
{
++redrawing_for_callback;
if (State == HITRETURN || State == ASKMORE)
;
else if (State & CMDLINE)
{
if (msg_scrolled == 0
#ifdef FEAT_WILDMENU
&& wild_menu_showing == 0
#endif
&& call_update_screen)
update_screen(0);
redrawcmdline_ex(FALSE);
}
else if (State & (NORMAL | INSERT | TERMINAL))
{
update_screen(VALID_NO_UPDATE);
setcursor();
}
cursor_on();
out_flush();
#ifdef FEAT_GUI
if (gui.in_use)
{
if (!gui_mch_is_blink_off())
gui_update_cursor(FALSE, FALSE);
gui_mch_flush();
}
#endif
--redrawing_for_callback;
}
void
redrawWinline(
linenr_T lnum,
int invalid UNUSED)
{
#ifdef FEAT_FOLDING
int i;
#endif
if (curwin->w_redraw_top == 0 || curwin->w_redraw_top > lnum)
curwin->w_redraw_top = lnum;
if (curwin->w_redraw_bot == 0 || curwin->w_redraw_bot < lnum)
curwin->w_redraw_bot = lnum;
redraw_later(VALID);
#ifdef FEAT_FOLDING
if (invalid)
{
i = find_wl_entry(curwin, lnum);
if (i >= 0)
curwin->w_lines[i].wl_valid = FALSE;
}
#endif
}
void
update_curbuf(int type)
{
redraw_curbuf_later(type);
update_screen(type);
}
int
update_screen(int type_arg)
{
int type = type_arg;
win_T *wp;
static int did_intro = FALSE;
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
int did_one;
#endif
#ifdef FEAT_GUI
int did_undraw = FALSE;
int gui_cursor_col;
int gui_cursor_row;
#endif
int no_update = FALSE;
if (!screen_valid(TRUE))
return FAIL;
if (type == VALID_NO_UPDATE)
{
no_update = TRUE;
type = 0;
}
if (must_redraw)
{
if (type < must_redraw)
type = must_redraw;
must_redraw = 0;
}
if (curwin->w_lines_valid == 0 && type < NOT_VALID)
type = NOT_VALID;
if (!redrawing() || updating_screen)
{
redraw_later(type);
must_redraw = type;
if (type > INVERTED_ALL)
curwin->w_lines_valid = 0;
return FAIL;
}
updating_screen = TRUE;
#ifdef FEAT_SYN_HL
++display_tick;
#endif
if (no_update)
++no_win_do_lines_ins;
if (msg_scrolled)
{
clear_cmdline = TRUE;
if (msg_scrolled > Rows - 5)
type = CLEAR;
else if (type != CLEAR)
{
check_for_delay(FALSE);
if (screen_ins_lines(0, 0, msg_scrolled, (int)Rows, 0, NULL)
== FAIL)
type = CLEAR;
FOR_ALL_WINDOWS(wp)
{
if (W_WINROW(wp) < msg_scrolled)
{
if (W_WINROW(wp) + wp->w_height > msg_scrolled
&& wp->w_redr_type < REDRAW_TOP
&& wp->w_lines_valid > 0
&& wp->w_topline == wp->w_lines[0].wl_lnum)
{
wp->w_upd_rows = msg_scrolled - W_WINROW(wp);
wp->w_redr_type = REDRAW_TOP;
}
else
{
wp->w_redr_type = NOT_VALID;
if (W_WINROW(wp) + wp->w_height + wp->w_status_height
<= msg_scrolled)
wp->w_redr_status = TRUE;
}
}
}
if (!no_update)
redraw_cmdline = TRUE;
redraw_tabline = TRUE;
}
msg_scrolled = 0;
need_wait_return = FALSE;
}
compute_cmdrow();
if (need_highlight_changed)
highlight_changed();
if (type == CLEAR)
{
screenclear();
type = NOT_VALID;
must_redraw = 0;
}
if (clear_cmdline)
check_for_delay(FALSE);
#ifdef FEAT_LINEBREAK
if (curwin->w_redr_type < NOT_VALID
&& curwin->w_nrwidth != ((curwin->w_p_nu || curwin->w_p_rnu)
? number_width(curwin) : 0))
curwin->w_redr_type = NOT_VALID;
#endif
if (type == INVERTED)
update_curswant();
if (curwin->w_redr_type < type
&& !((type == VALID
&& curwin->w_lines[0].wl_valid
#ifdef FEAT_DIFF
&& curwin->w_topfill == curwin->w_old_topfill
&& curwin->w_botfill == curwin->w_old_botfill
#endif
&& curwin->w_topline == curwin->w_lines[0].wl_lnum)
|| (type == INVERTED
&& VIsual_active
&& curwin->w_old_cursor_lnum == curwin->w_cursor.lnum
&& curwin->w_old_visual_mode == VIsual_mode
&& (curwin->w_valid & VALID_VIRTCOL)
&& curwin->w_old_curswant == curwin->w_curswant)
))
curwin->w_redr_type = type;
if (redraw_tabline || type >= NOT_VALID)
draw_tabline();
#ifdef FEAT_SYN_HL
FOR_ALL_WINDOWS(wp)
{
if (wp->w_buffer->b_mod_set)
{
win_T *wwp;
for (wwp = firstwin; wwp != wp; wwp = wwp->w_next)
if (wwp->w_buffer == wp->w_buffer)
break;
if (wwp == wp && syntax_present(wp))
syn_stack_apply_changes(wp->w_buffer);
}
}
#endif
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
did_one = FALSE;
#endif
#ifdef FEAT_SEARCH_EXTRA
search_hl.rm.regprog = NULL;
#endif
FOR_ALL_WINDOWS(wp)
{
if (wp->w_redr_type != 0)
{
cursor_off();
#if defined(FEAT_SEARCH_EXTRA) || defined(FEAT_CLIPBOARD)
if (!did_one)
{
did_one = TRUE;
# ifdef FEAT_SEARCH_EXTRA
start_search_hl();
# endif
# ifdef FEAT_CLIPBOARD
if (clip_star.available && clip_isautosel_star())
clip_update_selection(&clip_star);
if (clip_plus.available && clip_isautosel_plus())
clip_update_selection(&clip_plus);
# endif
#ifdef FEAT_GUI
if (gui.in_use && wp == curwin)
{
gui_cursor_col = gui.cursor_col;
gui_cursor_row = gui.cursor_row;
gui_undraw_cursor();
did_undraw = TRUE;
}
#endif
}
#endif
win_update(wp);
}
if (wp->w_redr_status)
{
cursor_off();
win_redr_status(wp);
}
}
#if defined(FEAT_SEARCH_EXTRA)
end_search_hl();
#endif
#ifdef FEAT_INS_EXPAND
if (pum_visible())
pum_redraw();
#endif
FOR_ALL_WINDOWS(wp)
wp->w_buffer->b_mod_set = FALSE;
updating_screen = FALSE;
#ifdef FEAT_GUI
gui_may_resize_shell();
#endif
if (clear_cmdline || redraw_cmdline)
showmode();
if (no_update)
--no_win_do_lines_ins;
if (!did_intro)
maybe_intro_message();
did_intro = TRUE;
#ifdef FEAT_GUI
if (gui.in_use)
{
out_flush();
if (did_undraw && !gui_mch_is_blink_off())
{
gui.col = gui_cursor_col;
gui.row = gui_cursor_row;
# ifdef FEAT_MBYTE
gui.col = mb_fix_col(gui.col, gui.row);
# endif
gui_update_cursor(FALSE, FALSE);
screen_cur_col = gui.col;
screen_cur_row = gui.row;
}
gui_update_scrollbars(FALSE);
}
#endif
return OK;
}
#if defined(FEAT_SIGNS) || defined(FEAT_GUI) || defined(FEAT_CONCEAL)
static void
update_prepare(void)
{
cursor_off();
updating_screen = TRUE;
#ifdef FEAT_GUI
if (gui.in_use)
gui_undraw_cursor();
#endif
#ifdef FEAT_SEARCH_EXTRA
start_search_hl();
#endif
}
static void
update_finish(void)
{
if (redraw_cmdline)
showmode();
# ifdef FEAT_SEARCH_EXTRA
end_search_hl();
# endif
updating_screen = FALSE;
# ifdef FEAT_GUI
gui_may_resize_shell();
if (gui.in_use)
{
out_flush();
gui_update_cursor(FALSE, FALSE);
gui_update_scrollbars(FALSE);
}
# endif
}
#endif
#if defined(FEAT_CONCEAL) || defined(PROTO)
int
conceal_cursor_line(win_T *wp)
{
int c;
if (*wp->w_p_cocu == NUL)
return FALSE;
if (get_real_state() & VISUAL)
c = 'v';
else if (State & INSERT)
c = 'i';
else if (State & NORMAL)
c = 'n';
else if (State & CMDLINE)
c = 'c';
else
return FALSE;
return vim_strchr(wp->w_p_cocu, c) != NULL;
}
void
conceal_check_cursur_line(void)
{
if (curwin->w_p_cole > 0 && conceal_cursor_line(curwin))
{
need_cursor_line_redraw = TRUE;
curs_columns(TRUE);
}
}
void
update_single_line(win_T *wp, linenr_T lnum)
{
int row;
int j;
#ifdef SYN_TIME_LIMIT
proftime_T syntax_tm;
#endif
if (!screen_valid(TRUE) || updating_screen)
return;
if (lnum >= wp->w_topline && lnum < wp->w_botline
&& foldedCount(wp, lnum, &win_foldinfo) == 0)
{
#ifdef SYN_TIME_LIMIT
profile_setlimit(p_rdt, &syntax_tm);
syn_set_timeout(&syntax_tm);
#endif
update_prepare();
row = 0;
for (j = 0; j < wp->w_lines_valid; ++j)
{
if (lnum == wp->w_lines[j].wl_lnum)
{
screen_start();
# ifdef FEAT_SEARCH_EXTRA
init_search_hl(wp);
start_search_hl();
prepare_search_hl(wp, lnum);
# endif
win_line(wp, lnum, row, row + wp->w_lines[j].wl_size, FALSE);
# if defined(FEAT_SEARCH_EXTRA)
end_search_hl();
# endif
break;
}
row += wp->w_lines[j].wl_size;
}
update_finish();
#ifdef SYN_TIME_LIMIT
syn_set_timeout(NULL);
#endif
}
need_cursor_line_redraw = FALSE;
}
#endif
#if defined(FEAT_SIGNS) || defined(PROTO)
void
update_debug_sign(buf_T *buf, linenr_T lnum)
{
win_T *wp;
int doit = FALSE;
# ifdef FEAT_FOLDING
win_foldinfo.fi_level = 0;
# endif
FOR_ALL_WINDOWS(wp)
{
if (buf != NULL && lnum > 0)
{
if (wp->w_buffer == buf && lnum >= wp->w_topline
&& lnum < wp->w_botline)
{
if (wp->w_redraw_top == 0 || wp->w_redraw_top > lnum)
wp->w_redraw_top = lnum;
if (wp->w_redraw_bot == 0 || wp->w_redraw_bot < lnum)
wp->w_redraw_bot = lnum;
redraw_win_later(wp, VALID);
}
}
else
redraw_win_later(wp, VALID);
if (wp->w_redr_type != 0)
doit = TRUE;
}
if (!doit || updating_screen
|| State == ASKMORE || State == HITRETURN
|| msg_scrolled
#ifdef FEAT_GUI
|| gui.starting
#endif
|| starting)
return;
update_prepare();
FOR_ALL_WINDOWS(wp)
{
if (wp->w_redr_type != 0)
win_update(wp);
if (wp->w_redr_status)
win_redr_status(wp);
}
update_finish();
}
#endif
#if defined(FEAT_GUI) || defined(PROTO)
void
updateWindow(win_T *wp)
{
if (updating_screen)
return;
update_prepare();
#ifdef FEAT_CLIPBOARD
if (clip_star.available && clip_isautosel_star())
clip_update_selection(&clip_star);
if (clip_plus.available && clip_isautosel_plus())
clip_update_selection(&clip_plus);
#endif
win_update(wp);
if (redraw_tabline)
draw_tabline();
if (wp->w_redr_status
# ifdef FEAT_CMDL_INFO
|| p_ru
# endif
# ifdef FEAT_STL_OPT
|| *p_stl != NUL || *wp->w_p_stl != NUL
# endif
)
win_redr_status(wp);
update_finish();
}
#endif
static void
win_update(win_T *wp)
{
buf_T *buf = wp->w_buffer;
int type;
int top_end = 0;
int mid_start = 999;
int mid_end = 0;
int bot_start = 999;
int scrolled_down = FALSE;
#ifdef FEAT_SEARCH_EXTRA
matchitem_T *cur;
int top_to_mod = FALSE;
#endif
int row;
linenr_T lnum;
int idx;
int srow;
int eof = FALSE;
int didline = FALSE;
int i;
long j;
static int recursive = FALSE;
int old_botline = wp->w_botline;
#ifdef FEAT_FOLDING
long fold_count;
#endif
#ifdef FEAT_SYN_HL
#define DID_NONE 1
#define DID_LINE 2
#define DID_FOLD 3
int did_update = DID_NONE;
linenr_T syntax_last_parsed = 0;
#endif
linenr_T mod_top = 0;
linenr_T mod_bot = 0;
#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
int save_got_int;
#endif
#ifdef SYN_TIME_LIMIT
proftime_T syntax_tm;
#endif
type = wp->w_redr_type;
if (type == NOT_VALID)
{
wp->w_redr_status = TRUE;
wp->w_lines_valid = 0;
}
if (wp->w_height == 0)
{
wp->w_redr_type = 0;
return;
}
if (wp->w_width == 0)
{
draw_vsep_win(wp, 0);
wp->w_redr_type = 0;
return;
}
#ifdef FEAT_TERMINAL
if (term_update_window(wp) == OK)
{
wp->w_redr_type = 0;
return;
}
#endif
#ifdef FEAT_SEARCH_EXTRA
init_search_hl(wp);
#endif
#ifdef FEAT_LINEBREAK
i = (wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) : 0;
if (wp->w_nrwidth != i)
{
type = NOT_VALID;
wp->w_nrwidth = i;
}
else
#endif
if (buf->b_mod_set && buf->b_mod_xlines != 0 && wp->w_redraw_top != 0)
{
type = NOT_VALID;
}
else
{
mod_top = wp->w_redraw_top;
if (wp->w_redraw_bot != 0)
mod_bot = wp->w_redraw_bot + 1;
else
mod_bot = 0;
wp->w_redraw_top = 0;
wp->w_redraw_bot = 0;
if (buf->b_mod_set)
{
if (mod_top == 0 || mod_top > buf->b_mod_top)
{
mod_top = buf->b_mod_top;
#ifdef FEAT_SYN_HL
if (syntax_present(wp))
{
mod_top -= buf->b_s.b_syn_sync_linebreaks;
if (mod_top < 1)
mod_top = 1;
}
#endif
}
if (mod_bot == 0 || mod_bot < buf->b_mod_bot)
mod_bot = buf->b_mod_bot;
#ifdef FEAT_SEARCH_EXTRA
if (search_hl.rm.regprog != NULL
&& re_multiline(search_hl.rm.regprog))
top_to_mod = TRUE;
else
{
cur = wp->w_match_head;
while (cur != NULL)
{
if (cur->match.regprog != NULL
&& re_multiline(cur->match.regprog))
{
top_to_mod = TRUE;
break;
}
cur = cur->next;
}
}
#endif
}
#ifdef FEAT_FOLDING
if (mod_top != 0 && hasAnyFolding(wp))
{
linenr_T lnumt, lnumb;
lnumt = wp->w_topline;
lnumb = MAXLNUM;
for (i = 0; i < wp->w_lines_valid; ++i)
if (wp->w_lines[i].wl_valid)
{
if (wp->w_lines[i].wl_lastlnum < mod_top)
lnumt = wp->w_lines[i].wl_lastlnum + 1;
if (lnumb == MAXLNUM && wp->w_lines[i].wl_lnum >= mod_bot)
{
lnumb = wp->w_lines[i].wl_lnum;
if (compute_foldcolumn(wp, 0) > 0)
++lnumb;
}
}
(void)hasFoldingWin(wp, mod_top, &mod_top, NULL, TRUE, NULL);
if (mod_top > lnumt)
mod_top = lnumt;
--mod_bot;
(void)hasFoldingWin(wp, mod_bot, NULL, &mod_bot, TRUE, NULL);
++mod_bot;
if (mod_bot < lnumb)
mod_bot = lnumb;
}
#endif
if (mod_top != 0 && mod_top < wp->w_topline)
{
if (mod_bot > wp->w_topline)
mod_top = wp->w_topline;
#ifdef FEAT_SYN_HL
else if (syntax_present(wp))
top_end = 1;
#endif
}
if (mod_top != 0 && buf->b_mod_xlines != 0 && wp->w_p_nu)
mod_bot = MAXLNUM;
}
if (type == REDRAW_TOP)
{
j = 0;
for (i = 0; i < wp->w_lines_valid; ++i)
{
j += wp->w_lines[i].wl_size;
if (j >= wp->w_upd_rows)
{
top_end = j;
break;
}
}
if (top_end == 0)
type = NOT_VALID;
else
type = VALID;
}
if (screen_cleared)
screen_cleared = MAYBE;
if ((type == VALID || type == SOME_VALID
|| type == INVERTED || type == INVERTED_ALL)
#ifdef FEAT_DIFF
&& !wp->w_botfill && !wp->w_old_botfill
#endif
)
{
if (mod_top != 0 && wp->w_topline == mod_top)
{
}
else if (wp->w_lines[0].wl_valid
&& (wp->w_topline < wp->w_lines[0].wl_lnum
#ifdef FEAT_DIFF
|| (wp->w_topline == wp->w_lines[0].wl_lnum
&& wp->w_topfill > wp->w_old_topfill)
#endif
))
{
#ifdef FEAT_FOLDING
if (hasAnyFolding(wp))
{
linenr_T ln;
j = 0;
for (ln = wp->w_topline; ln < wp->w_lines[0].wl_lnum; ++ln)
{
++j;
if (j >= wp->w_height - 2)
break;
(void)hasFoldingWin(wp, ln, NULL, &ln, TRUE, NULL);
}
}
else
#endif
j = wp->w_lines[0].wl_lnum - wp->w_topline;
if (j < wp->w_height - 2)
{
i = plines_m_win(wp, wp->w_topline, wp->w_lines[0].wl_lnum - 1);
#ifdef FEAT_DIFF
if (wp->w_lines[0].wl_lnum != wp->w_topline)
i += diff_check_fill(wp, wp->w_lines[0].wl_lnum)
- wp->w_old_topfill;
#endif
if (i < wp->w_height - 2)
{
if (i > 0)
check_for_delay(FALSE);
if (win_ins_lines(wp, 0, i, FALSE, wp == firstwin) == OK)
{
if (wp->w_lines_valid != 0)
{
top_end = i;
scrolled_down = TRUE;
if ((wp->w_lines_valid += j) > wp->w_height)
wp->w_lines_valid = wp->w_height;
for (idx = wp->w_lines_valid; idx - j >= 0; idx--)
wp->w_lines[idx] = wp->w_lines[idx - j];
while (idx >= 0)
wp->w_lines[idx--].wl_valid = FALSE;
}
}
else
mid_start = 0;
}
else
mid_start = 0;
}
else
mid_start = 0;
}
else
{
j = -1;
row = 0;
for (i = 0; i < wp->w_lines_valid; i++)
{
if (wp->w_lines[i].wl_valid
&& wp->w_lines[i].wl_lnum == wp->w_topline)
{
j = i;
break;
}
row += wp->w_lines[i].wl_size;
}
if (j == -1)
{
mid_start = 0;
}
else
{
#ifdef FEAT_DIFF
if (wp->w_lines[0].wl_lnum == wp->w_topline)
row += wp->w_old_topfill;
else
row += diff_check_fill(wp, wp->w_topline);
row -= wp->w_topfill;
#endif
if (row > 0)
{
check_for_delay(FALSE);
if (win_del_lines(wp, 0, row, FALSE, wp == firstwin, 0)
== OK)
bot_start = wp->w_height - row;
else
mid_start = 0;
}
if ((row == 0 || bot_start < 999) && wp->w_lines_valid != 0)
{
bot_start = 0;
idx = 0;
for (;;)
{
wp->w_lines[idx] = wp->w_lines[j];
if (row > 0 && bot_start + row
+ (int)wp->w_lines[j].wl_size > wp->w_height)
{
wp->w_lines_valid = idx + 1;
break;
}
bot_start += wp->w_lines[idx++].wl_size;
if (++j >= wp->w_lines_valid)
{
wp->w_lines_valid = idx;
break;
}
}
#ifdef FEAT_DIFF
if (wp->w_p_diff && bot_start > 0)
wp->w_lines[0].wl_size =
plines_win_nofill(wp, wp->w_topline, TRUE)
+ wp->w_topfill;
#endif
}
}
}
if (mid_start == 0)
{
mid_end = wp->w_height;
if (ONE_WINDOW)
{
if (screen_cleared != TRUE)
screenclear();
if (redraw_tabline)
draw_tabline();
}
}
if (screen_cleared == TRUE)
must_redraw = 0;
}
else
{
mid_start = 0;
mid_end = wp->w_height;
}
if (type == SOME_VALID)
{
mid_start = 0;
mid_end = wp->w_height;
type = NOT_VALID;
}
if ((VIsual_active && buf == curwin->w_buffer)
|| (wp->w_old_cursor_lnum != 0 && type != NOT_VALID))
{
linenr_T from, to;
if (VIsual_active)
{
if (VIsual_active
&& (VIsual_mode != wp->w_old_visual_mode
|| type == INVERTED_ALL))
{
if (curwin->w_cursor.lnum < VIsual.lnum)
{
from = curwin->w_cursor.lnum;
to = VIsual.lnum;
}
else
{
from = VIsual.lnum;
to = curwin->w_cursor.lnum;
}
if (wp->w_old_cursor_lnum < from)
from = wp->w_old_cursor_lnum;
if (wp->w_old_cursor_lnum > to)
to = wp->w_old_cursor_lnum;
if (wp->w_old_visual_lnum < from)
from = wp->w_old_visual_lnum;
if (wp->w_old_visual_lnum > to)
to = wp->w_old_visual_lnum;
}
else
{
if (curwin->w_cursor.lnum < wp->w_old_cursor_lnum)
{
from = curwin->w_cursor.lnum;
to = wp->w_old_cursor_lnum;
}
else
{
from = wp->w_old_cursor_lnum;
to = curwin->w_cursor.lnum;
if (from == 0)
from = to;
}
if (VIsual.lnum != wp->w_old_visual_lnum
|| VIsual.col != wp->w_old_visual_col)
{
if (wp->w_old_visual_lnum < from
&& wp->w_old_visual_lnum != 0)
from = wp->w_old_visual_lnum;
if (wp->w_old_visual_lnum > to)
to = wp->w_old_visual_lnum;
if (VIsual.lnum < from)
from = VIsual.lnum;
if (VIsual.lnum > to)
to = VIsual.lnum;
}
}
if (VIsual_mode == Ctrl_V)
{
colnr_T fromc, toc;
#if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK)
int save_ve_flags = ve_flags;
if (curwin->w_p_lbr)
ve_flags = VE_ALL;
#endif
getvcols(wp, &VIsual, &curwin->w_cursor, &fromc, &toc);
#if defined(FEAT_VIRTUALEDIT) && defined(FEAT_LINEBREAK)
ve_flags = save_ve_flags;
#endif
++toc;
if (curwin->w_curswant == MAXCOL)
toc = MAXCOL;
if (fromc != wp->w_old_cursor_fcol
|| toc != wp->w_old_cursor_lcol)
{
if (from > VIsual.lnum)
from = VIsual.lnum;
if (to < VIsual.lnum)
to = VIsual.lnum;
}
wp->w_old_cursor_fcol = fromc;
wp->w_old_cursor_lcol = toc;
}
}
else
{
if (wp->w_old_cursor_lnum < wp->w_old_visual_lnum)
{
from = wp->w_old_cursor_lnum;
to = wp->w_old_visual_lnum;
}
else
{
from = wp->w_old_visual_lnum;
to = wp->w_old_cursor_lnum;
}
}
if (from < wp->w_topline)
from = wp->w_topline;
if (wp->w_valid & VALID_BOTLINE)
{
if (from >= wp->w_botline)
from = wp->w_botline - 1;
if (to >= wp->w_botline)
to = wp->w_botline - 1;
}
if (mid_start > 0)
{
lnum = wp->w_topline;
idx = 0;
srow = 0;
if (scrolled_down)
mid_start = top_end;
else
mid_start = 0;
while (lnum < from && idx < wp->w_lines_valid)
{
if (wp->w_lines[idx].wl_valid)
mid_start += wp->w_lines[idx].wl_size;
else if (!scrolled_down)
srow += wp->w_lines[idx].wl_size;
++idx;
# ifdef FEAT_FOLDING
if (idx < wp->w_lines_valid && wp->w_lines[idx].wl_valid)
lnum = wp->w_lines[idx].wl_lnum;
else
# endif
++lnum;
}
srow += mid_start;
mid_end = wp->w_height;
for ( ; idx < wp->w_lines_valid; ++idx)
{
if (wp->w_lines[idx].wl_valid
&& wp->w_lines[idx].wl_lnum >= to + 1)
{
mid_end = srow;
break;
}
srow += wp->w_lines[idx].wl_size;
}
}
}
if (VIsual_active && buf == curwin->w_buffer)
{
wp->w_old_visual_mode = VIsual_mode;
wp->w_old_cursor_lnum = curwin->w_cursor.lnum;
wp->w_old_visual_lnum = VIsual.lnum;
wp->w_old_visual_col = VIsual.col;
wp->w_old_curswant = curwin->w_curswant;
}
else
{
wp->w_old_visual_mode = 0;
wp->w_old_cursor_lnum = 0;
wp->w_old_visual_lnum = 0;
wp->w_old_visual_col = 0;
}
#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
save_got_int = got_int;
got_int = 0;
#endif
#ifdef SYN_TIME_LIMIT
profile_setlimit(p_rdt, &syntax_tm);
syn_set_timeout(&syntax_tm);
#endif
#ifdef FEAT_FOLDING
win_foldinfo.fi_level = 0;
#endif
#ifdef FEAT_MENU
if (winbar_height(wp) > 0)
redraw_win_toolbar(wp);
#endif
idx = 0;
row = 0;
srow = 0;
lnum = wp->w_topline;
for (;;)
{
if (row == wp->w_height)
{
didline = TRUE;
break;
}
if (lnum > buf->b_ml.ml_line_count)
{
eof = TRUE;
break;
}
srow = row;
if (row < top_end
|| (row >= mid_start && row < mid_end)
#ifdef FEAT_SEARCH_EXTRA
|| top_to_mod
#endif
|| idx >= wp->w_lines_valid
|| (row + wp->w_lines[idx].wl_size > bot_start)
|| (mod_top != 0
&& (lnum == mod_top
|| (lnum >= mod_top
&& (lnum < mod_bot
#ifdef FEAT_SYN_HL
|| did_update == DID_FOLD
|| (did_update == DID_LINE
&& syntax_present(wp)
&& (
# ifdef FEAT_FOLDING
(foldmethodIsSyntax(wp)
&& hasAnyFolding(wp)) ||
# endif
syntax_check_changed(lnum)))
#endif
#ifdef FEAT_SEARCH_EXTRA
|| (wp->w_match_head != NULL
&& buf->b_mod_xlines != 0)
#endif
)))))
{
#ifdef FEAT_SEARCH_EXTRA
if (lnum == mod_top)
top_to_mod = FALSE;
#endif
if (lnum == mod_top
&& mod_bot != MAXLNUM
&& !(dollar_vcol >= 0 && mod_bot == mod_top + 1))
{
int old_rows = 0;
int new_rows = 0;
int xtra_rows;
linenr_T l;
for (i = idx; i < wp->w_lines_valid; ++i)
{
if (wp->w_lines[i].wl_valid
&& wp->w_lines[i].wl_lnum == mod_bot)
break;
old_rows += wp->w_lines[i].wl_size;
#ifdef FEAT_FOLDING
if (wp->w_lines[i].wl_valid
&& wp->w_lines[i].wl_lastlnum + 1 == mod_bot)
{
++i;
while (i < wp->w_lines_valid
&& !wp->w_lines[i].wl_valid)
old_rows += wp->w_lines[i++].wl_size;
break;
}
#endif
}
if (i >= wp->w_lines_valid)
{
bot_start = 0;
}
else
{
j = idx;
for (l = lnum; l < mod_bot; ++l)
{
#ifdef FEAT_FOLDING
if (hasFoldingWin(wp, l, NULL, &l, TRUE, NULL))
++new_rows;
else
#endif
#ifdef FEAT_DIFF
if (l == wp->w_topline)
new_rows += plines_win_nofill(wp, l, TRUE)
+ wp->w_topfill;
else
#endif
new_rows += plines_win(wp, l, TRUE);
++j;
if (new_rows > wp->w_height - row - 2)
{
new_rows = 9999;
break;
}
}
xtra_rows = new_rows - old_rows;
if (xtra_rows < 0)
{
if (row - xtra_rows >= wp->w_height - 2)
mod_bot = MAXLNUM;
else
{
check_for_delay(FALSE);
if (win_del_lines(wp, row,
-xtra_rows, FALSE, FALSE, 0) == FAIL)
mod_bot = MAXLNUM;
else
bot_start = wp->w_height + xtra_rows;
}
}
else if (xtra_rows > 0)
{
if (row + xtra_rows >= wp->w_height - 2)
mod_bot = MAXLNUM;
else
{
check_for_delay(FALSE);
if (win_ins_lines(wp, row + old_rows,
xtra_rows, FALSE, FALSE) == FAIL)
mod_bot = MAXLNUM;
else if (top_end > row + old_rows)
top_end += xtra_rows;
}
}
if (mod_bot != MAXLNUM && i != j)
{
if (j < i)
{
int x = row + new_rows;
for (;;)
{
if (i >= wp->w_lines_valid)
{
wp->w_lines_valid = j;
break;
}
wp->w_lines[j] = wp->w_lines[i];
if (x + (int)wp->w_lines[j].wl_size
> wp->w_height)
{
wp->w_lines_valid = j + 1;
break;
}
x += wp->w_lines[j++].wl_size;
++i;
}
if (bot_start > x)
bot_start = x;
}
else
{
j -= i;
wp->w_lines_valid += j;
if (wp->w_lines_valid > wp->w_height)
wp->w_lines_valid = wp->w_height;
for (i = wp->w_lines_valid; i - j >= idx; --i)
wp->w_lines[i] = wp->w_lines[i - j];
while (i >= idx)
{
wp->w_lines[i].wl_size = 0;
wp->w_lines[i--].wl_valid = FALSE;
}
}
}
}
}
#ifdef FEAT_FOLDING
fold_count = foldedCount(wp, lnum, &win_foldinfo);
if (fold_count != 0)
{
fold_line(wp, fold_count, &win_foldinfo, lnum, row);
++row;
--fold_count;
wp->w_lines[idx].wl_folded = TRUE;
wp->w_lines[idx].wl_lastlnum = lnum + fold_count;
# ifdef FEAT_SYN_HL
did_update = DID_FOLD;
# endif
}
else
#endif
if (idx < wp->w_lines_valid
&& wp->w_lines[idx].wl_valid
&& wp->w_lines[idx].wl_lnum == lnum
&& lnum > wp->w_topline
&& !(dy_flags & (DY_LASTLINE | DY_TRUNCATE))
&& srow + wp->w_lines[idx].wl_size > wp->w_height
#ifdef FEAT_DIFF
&& diff_check_fill(wp, lnum) == 0
#endif
)
{
row = wp->w_height + 1;
}
else
{
#ifdef FEAT_SEARCH_EXTRA
prepare_search_hl(wp, lnum);
#endif
#ifdef FEAT_SYN_HL
if (syntax_last_parsed != 0 && syntax_last_parsed + 1 < lnum
&& syntax_present(wp))
syntax_end_parsing(syntax_last_parsed + 1);
#endif
row = win_line(wp, lnum, srow, wp->w_height, mod_top == 0);
#ifdef FEAT_FOLDING
wp->w_lines[idx].wl_folded = FALSE;
wp->w_lines[idx].wl_lastlnum = lnum;
#endif
#ifdef FEAT_SYN_HL
did_update = DID_LINE;
syntax_last_parsed = lnum;
#endif
}
wp->w_lines[idx].wl_lnum = lnum;
wp->w_lines[idx].wl_valid = TRUE;
if (row > wp->w_height || row + wp->w_winrow >= Rows)
{
if (dollar_vcol == -1)
wp->w_lines[idx].wl_size = plines_win(wp, lnum, TRUE);
++idx;
break;
}
if (dollar_vcol == -1)
wp->w_lines[idx].wl_size = row - srow;
++idx;
#ifdef FEAT_FOLDING
lnum += fold_count + 1;
#else
++lnum;
#endif
}
else
{
row += wp->w_lines[idx++].wl_size;
if (row > wp->w_height)
break;
#ifdef FEAT_FOLDING
lnum = wp->w_lines[idx - 1].wl_lastlnum + 1;
#else
++lnum;
#endif
#ifdef FEAT_SYN_HL
did_update = DID_NONE;
#endif
}
if (lnum > buf->b_ml.ml_line_count)
{
eof = TRUE;
break;
}
}
if (idx > wp->w_lines_valid)
wp->w_lines_valid = idx;
#ifdef FEAT_SYN_HL
if (syntax_last_parsed != 0 && syntax_present(wp))
syntax_end_parsing(syntax_last_parsed + 1);
#endif
wp->w_empty_rows = 0;
#ifdef FEAT_DIFF
wp->w_filler_rows = 0;
#endif
if (!eof && !didline)
{
if (lnum == wp->w_topline)
{
wp->w_botline = lnum + 1;
}
#ifdef FEAT_DIFF
else if (diff_check_fill(wp, lnum) >= wp->w_height - srow)
{
wp->w_botline = lnum;
wp->w_filler_rows = wp->w_height - srow;
}
#endif
else if (dy_flags & DY_TRUNCATE)
{
int scr_row = W_WINROW(wp) + wp->w_height - 1;
screen_puts_len((char_u *)"@@", 2, scr_row, wp->w_wincol,
HL_ATTR(HLF_AT));
screen_fill(scr_row, scr_row + 1,
(int)wp->w_wincol + 2, (int)W_ENDCOL(wp),
'@', ' ', HL_ATTR(HLF_AT));
set_empty_rows(wp, srow);
wp->w_botline = lnum;
}
else if (dy_flags & DY_LASTLINE)
{
screen_fill(W_WINROW(wp) + wp->w_height - 1,
W_WINROW(wp) + wp->w_height,
(int)W_ENDCOL(wp) - 3, (int)W_ENDCOL(wp),
'@', '@', HL_ATTR(HLF_AT));
set_empty_rows(wp, srow);
wp->w_botline = lnum;
}
else
{
win_draw_end(wp, '@', ' ', srow, wp->w_height, HLF_AT);
wp->w_botline = lnum;
}
}
else
{
draw_vsep_win(wp, row);
if (eof)
{
wp->w_botline = buf->b_ml.ml_line_count + 1;
#ifdef FEAT_DIFF
j = diff_check_fill(wp, wp->w_botline);
if (j > 0 && !wp->w_botfill)
{
if (char2cells(fill_diff) > 1)
i = '-';
else
i = fill_diff;
if (row + j > wp->w_height)
j = wp->w_height - row;
win_draw_end(wp, i, i, row, row + (int)j, HLF_DED);
row += j;
}
#endif
}
else if (dollar_vcol == -1)
wp->w_botline = lnum;
win_draw_end(wp, '~', ' ', row, wp->w_height, HLF_EOB);
}
#ifdef SYN_TIME_LIMIT
syn_set_timeout(NULL);
#endif
wp->w_redr_type = 0;
#ifdef FEAT_DIFF
wp->w_old_topfill = wp->w_topfill;
wp->w_old_botfill = wp->w_botfill;
#endif
if (dollar_vcol == -1)
{
wp->w_valid |= VALID_BOTLINE;
if (wp == curwin && wp->w_botline != old_botline && !recursive)
{
recursive = TRUE;
curwin->w_valid &= ~VALID_TOPLINE;
update_topline();
if (must_redraw != 0)
{
i = curbuf->b_mod_set;
curbuf->b_mod_set = FALSE;
win_update(curwin);
must_redraw = 0;
curbuf->b_mod_set = i;
}
recursive = FALSE;
}
}
#if defined(FEAT_SYN_HL) || defined(FEAT_SEARCH_EXTRA)
if (!got_int)
got_int = save_got_int;
#endif
}
static void
win_draw_end(
win_T *wp,
int c1,
int c2,
int row,
int endrow,
hlf_T hl)
{
#if defined(FEAT_FOLDING) || defined(FEAT_SIGNS) || defined(FEAT_CMDWIN)
int n = 0;
# define FDC_OFF n
#else
# define FDC_OFF 0
#endif
#ifdef FEAT_FOLDING
int fdc = compute_foldcolumn(wp, 0);
#endif
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
# ifdef FEAT_FOLDING
n = fdc;
if (n > 0)
{
if (n > wp->w_width)
n = wp->w_width;
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
W_ENDCOL(wp) - n, (int)W_ENDCOL(wp),
' ', ' ', HL_ATTR(HLF_FC));
}
# endif
# ifdef FEAT_SIGNS
if (signcolumn_on(wp))
{
int nn = n + 2;
if (nn > wp->w_width)
nn = wp->w_width;
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
W_ENDCOL(wp) - nn, (int)W_ENDCOL(wp) - n,
' ', ' ', HL_ATTR(HLF_SC));
n = nn;
}
# endif
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol, W_ENDCOL(wp) - 1 - FDC_OFF,
c2, c2, HL_ATTR(hl));
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
W_ENDCOL(wp) - 1 - FDC_OFF, W_ENDCOL(wp) - FDC_OFF,
c1, c2, HL_ATTR(hl));
}
else
#endif
{
#ifdef FEAT_CMDWIN
if (cmdwin_type != 0 && wp == curwin)
{
n = 1;
if (n > wp->w_width)
n = wp->w_width;
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol, (int)wp->w_wincol + n,
cmdwin_type, ' ', HL_ATTR(HLF_AT));
}
#endif
#ifdef FEAT_FOLDING
if (fdc > 0)
{
int nn = n + fdc;
if (nn > wp->w_width)
nn = wp->w_width;
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol + n, (int)wp->w_wincol + nn,
' ', ' ', HL_ATTR(HLF_FC));
n = nn;
}
#endif
#ifdef FEAT_SIGNS
if (signcolumn_on(wp))
{
int nn = n + 2;
if (nn > wp->w_width)
nn = wp->w_width;
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol + n, (int)wp->w_wincol + nn,
' ', ' ', HL_ATTR(HLF_SC));
n = nn;
}
#endif
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + endrow,
wp->w_wincol + FDC_OFF, (int)W_ENDCOL(wp),
c1, c2, HL_ATTR(hl));
}
set_empty_rows(wp, row);
}
#ifdef FEAT_SYN_HL
static int advance_color_col(int vcol, int **color_cols);
static int
advance_color_col(int vcol, int **color_cols)
{
while (**color_cols >= 0 && vcol > **color_cols)
++*color_cols;
return (**color_cols >= 0);
}
#endif
#if defined(FEAT_MENU) || defined(FEAT_FOLDING)
static int
text_to_screenline(win_T *wp, char_u *text, int col)
{
int off = (int)(current_ScreenLine - ScreenLines);
#ifdef FEAT_MBYTE
if (has_mbyte)
{
int cells;
int u8c, u8cc[MAX_MCO];
int i;
int idx;
int c_len;
char_u *p;
# ifdef FEAT_ARABIC
int prev_c = 0;
int prev_c1 = 0;
# endif
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
idx = off;
else
# endif
idx = off + col;
for (p = text; *p != NUL; )
{
cells = (*mb_ptr2cells)(p);
c_len = (*mb_ptr2len)(p);
if (col + cells > wp->w_width
# ifdef FEAT_RIGHTLEFT
- (wp->w_p_rl ? col : 0)
# endif
)
break;
ScreenLines[idx] = *p;
if (enc_utf8)
{
u8c = utfc_ptr2char(p, u8cc);
if (*p < 0x80 && u8cc[0] == 0)
{
ScreenLinesUC[idx] = 0;
#ifdef FEAT_ARABIC
prev_c = u8c;
#endif
}
else
{
#ifdef FEAT_ARABIC
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
{
int pc, pc1, nc;
int pcc[MAX_MCO];
int firstbyte = *p;
if (wp->w_p_rl)
{
pc = prev_c;
pc1 = prev_c1;
nc = utf_ptr2char(p + c_len);
prev_c1 = u8cc[0];
}
else
{
pc = utfc_ptr2char(p + c_len, pcc);
nc = prev_c;
pc1 = pcc[0];
}
prev_c = u8c;
u8c = arabic_shape(u8c, &firstbyte, &u8cc[0],
pc, pc1, nc);
ScreenLines[idx] = firstbyte;
}
else
prev_c = u8c;
#endif
#ifdef UNICODE16
if (u8c >= 0x10000)
ScreenLinesUC[idx] = (cells == 2) ? 0xff1f : (int)'?';
else
#endif
ScreenLinesUC[idx] = u8c;
for (i = 0; i < Screen_mco; ++i)
{
ScreenLinesC[i][idx] = u8cc[i];
if (u8cc[i] == 0)
break;
}
}
if (cells > 1)
ScreenLines[idx + 1] = 0;
}
else if (enc_dbcs == DBCS_JPNU && *p == 0x8e)
ScreenLines2[idx] = p[1];
else if (cells > 1)
ScreenLines[idx + 1] = p[1];
col += cells;
idx += cells;
p += c_len;
}
}
else
#endif
{
int len = (int)STRLEN(text);
if (len > wp->w_width - col)
len = wp->w_width - col;
if (len > 0)
{
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
STRNCPY(current_ScreenLine, text, len);
else
#endif
STRNCPY(current_ScreenLine + col, text, len);
col += len;
}
}
return col;
}
#endif
#ifdef FEAT_FOLDING
static int
compute_foldcolumn(win_T *wp, int col)
{
int fdc = wp->w_p_fdc;
int wmw = wp == curwin && p_wmw == 0 ? 1 : p_wmw;
int wwidth = wp->w_width;
if (fdc > wwidth - (col + wmw))
fdc = wwidth - (col + wmw);
return fdc;
}
static void
fold_line(
win_T *wp,
long fold_count,
foldinfo_T *foldinfo,
linenr_T lnum,
int row)
{
char_u buf[FOLD_TEXT_LEN];
pos_T *top, *bot;
linenr_T lnume = lnum + fold_count - 1;
int len;
char_u *text;
int fdc;
int col;
int txtcol;
int off = (int)(current_ScreenLine - ScreenLines);
int ri;
col = 0;
#ifdef FEAT_CMDWIN
if (cmdwin_type != 0 && wp == curwin)
{
ScreenLines[off] = cmdwin_type;
ScreenAttrs[off] = HL_ATTR(HLF_AT);
#ifdef FEAT_MBYTE
if (enc_utf8)
ScreenLinesUC[off] = 0;
#endif
++col;
}
#endif
fdc = compute_foldcolumn(wp, col);
if (fdc > 0)
{
fill_foldcolumn(buf, wp, TRUE, lnum);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
int i;
copy_text_attr(off + wp->w_width - fdc - col, buf, fdc,
HL_ATTR(HLF_FC));
for (i = 0; i < fdc; ++i)
ScreenLines[off + wp->w_width - i - 1 - col] = buf[i];
}
else
#endif
copy_text_attr(off + col, buf, fdc, HL_ATTR(HLF_FC));
col += fdc;
}
#ifdef FEAT_RIGHTLEFT
# define RL_MEMSET(p, v, l) if (wp->w_p_rl) \
for (ri = 0; ri < l; ++ri) \
ScreenAttrs[off + (wp->w_width - (p) - (l)) + ri] = v; \
else \
for (ri = 0; ri < l; ++ri) \
ScreenAttrs[off + (p) + ri] = v
#else
# define RL_MEMSET(p, v, l) for (ri = 0; ri < l; ++ri) \
ScreenAttrs[off + (p) + ri] = v
#endif
RL_MEMSET(col, HL_ATTR(HLF_FL), wp->w_width - col);
#ifdef FEAT_SIGNS
if (signcolumn_on(wp))
{
len = wp->w_width - col;
if (len > 0)
{
if (len > 2)
len = 2;
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
copy_text_attr(off + wp->w_width - len - col,
(char_u *)" ", len, HL_ATTR(HLF_FL));
else
# endif
copy_text_attr(off + col, (char_u *)" ", len, HL_ATTR(HLF_FL));
col += len;
}
}
#endif
if (wp->w_p_nu || wp->w_p_rnu)
{
len = wp->w_width - col;
if (len > 0)
{
int w = number_width(wp);
long num;
char *fmt = "%*ld ";
if (len > w + 1)
len = w + 1;
if (wp->w_p_nu && !wp->w_p_rnu)
num = (long)lnum;
else
{
num = labs((long)get_cursor_rel_lnum(wp, lnum));
if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
{
num = lnum;
fmt = "%-*ld ";
}
}
sprintf((char *)buf, fmt, w, num);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
copy_text_attr(off + wp->w_width - len - col, buf, len,
HL_ATTR(HLF_FL));
else
#endif
copy_text_attr(off + col, buf, len, HL_ATTR(HLF_FL));
col += len;
}
}
text = get_foldtext(wp, lnum, lnume, foldinfo, buf);
txtcol = col;
col = text_to_screenline(wp, text, col);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
col -= txtcol;
#endif
while (col < wp->w_width
#ifdef FEAT_RIGHTLEFT
- (wp->w_p_rl ? txtcol : 0)
#endif
)
{
#ifdef FEAT_MBYTE
if (enc_utf8)
{
if (fill_fold >= 0x80)
{
ScreenLinesUC[off + col] = fill_fold;
ScreenLinesC[0][off + col] = 0;
ScreenLines[off + col] = 0x80;
}
else
{
ScreenLinesUC[off + col] = 0;
ScreenLines[off + col] = fill_fold;
}
col++;
}
else
#endif
ScreenLines[off + col++] = fill_fold;
}
if (text != buf)
vim_free(text);
if (VIsual_active && wp->w_buffer == curwin->w_buffer)
{
if (LTOREQ_POS(curwin->w_cursor, VIsual))
{
top = &curwin->w_cursor;
bot = &VIsual;
}
else
{
top = &VIsual;
bot = &curwin->w_cursor;
}
if (lnum >= top->lnum
&& lnume <= bot->lnum
&& (VIsual_mode != 'v'
|| ((lnum > top->lnum
|| (lnum == top->lnum
&& top->col == 0))
&& (lnume < bot->lnum
|| (lnume == bot->lnum
&& (bot->col - (*p_sel == 'e'))
>= (colnr_T)STRLEN(ml_get_buf(wp->w_buffer, lnume, FALSE)))))))
{
if (VIsual_mode == Ctrl_V)
{
if (wp->w_old_cursor_fcol + txtcol < (colnr_T)wp->w_width)
{
if (wp->w_old_cursor_lcol != MAXCOL
&& wp->w_old_cursor_lcol + txtcol
< (colnr_T)wp->w_width)
len = wp->w_old_cursor_lcol;
else
len = wp->w_width - txtcol;
RL_MEMSET(wp->w_old_cursor_fcol + txtcol, HL_ATTR(HLF_V),
len - (int)wp->w_old_cursor_fcol);
}
}
else
{
RL_MEMSET(txtcol, HL_ATTR(HLF_V), wp->w_width - txtcol);
}
}
}
#ifdef FEAT_SYN_HL
if (wp->w_p_cc_cols)
{
int i = 0;
int j = wp->w_p_cc_cols[i];
int old_txtcol = txtcol;
while (j > -1)
{
txtcol += j;
if (wp->w_p_wrap)
txtcol -= wp->w_skipcol;
else
txtcol -= wp->w_leftcol;
if (txtcol >= 0 && txtcol < wp->w_width)
ScreenAttrs[off + txtcol] = hl_combine_attr(
ScreenAttrs[off + txtcol], HL_ATTR(HLF_MC));
txtcol = old_txtcol;
j = wp->w_p_cc_cols[++i];
}
}
if (wp->w_p_cuc)
{
txtcol += wp->w_virtcol;
if (wp->w_p_wrap)
txtcol -= wp->w_skipcol;
else
txtcol -= wp->w_leftcol;
if (txtcol >= 0 && txtcol < wp->w_width)
ScreenAttrs[off + txtcol] = hl_combine_attr(
ScreenAttrs[off + txtcol], HL_ATTR(HLF_CUC));
}
#endif
screen_line(row + W_WINROW(wp), wp->w_wincol, (int)wp->w_width,
(int)wp->w_width, FALSE);
if (wp == curwin
&& lnum <= curwin->w_cursor.lnum
&& lnume >= curwin->w_cursor.lnum)
{
curwin->w_cline_row = row;
curwin->w_cline_height = 1;
curwin->w_cline_folded = TRUE;
curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
}
}
static void
copy_text_attr(
int off,
char_u *buf,
int len,
int attr)
{
int i;
mch_memmove(ScreenLines + off, buf, (size_t)len);
# ifdef FEAT_MBYTE
if (enc_utf8)
vim_memset(ScreenLinesUC + off, 0, sizeof(u8char_T) * (size_t)len);
# endif
for (i = 0; i < len; ++i)
ScreenAttrs[off + i] = attr;
}
static void
fill_foldcolumn(
char_u *p,
win_T *wp,
int closed,
linenr_T lnum)
{
int i = 0;
int level;
int first_level;
int empty;
int fdc = compute_foldcolumn(wp, 0);
vim_memset(p, ' ', (size_t)fdc);
level = win_foldinfo.fi_level;
if (level > 0)
{
empty = (fdc == 1) ? 0 : 1;
first_level = level - fdc - closed + 1 + empty;
if (first_level < 1)
first_level = 1;
for (i = 0; i + empty < fdc; ++i)
{
if (win_foldinfo.fi_lnum == lnum
&& first_level + i >= win_foldinfo.fi_low_level)
p[i] = '-';
else if (first_level == 1)
p[i] = '|';
else if (first_level + i <= 9)
p[i] = '0' + first_level + i;
else
p[i] = '>';
if (first_level + i == level)
break;
}
}
if (closed)
p[i >= fdc ? i - 1 : i] = '+';
}
#endif
static int
win_line(
win_T *wp,
linenr_T lnum,
int startrow,
int endrow,
int nochange UNUSED)
{
int col = 0;
unsigned off;
int c = 0;
long vcol = 0;
#ifdef FEAT_LINEBREAK
long vcol_sbr = -1;
#endif
long vcol_prev = -1;
char_u *line;
char_u *ptr;
int row;
int screen_row;
char_u extra[18];
int n_extra = 0;
char_u *p_extra = NULL;
char_u *p_extra_free = NULL;
int c_extra = NUL;
int extra_attr = 0;
static char_u *at_end_str = (char_u *)"";
int lcs_eol_one = lcs_eol;
int lcs_prec_todo = lcs_prec;
int saved_n_extra = 0;
char_u *saved_p_extra = NULL;
int saved_c_extra = 0;
int saved_char_attr = 0;
int n_attr = 0;
int saved_attr2 = 0;
int n_attr3 = 0;
int saved_attr3 = 0;
int n_skip = 0;
int fromcol, tocol;
int fromcol_prev = -2;
int noinvcur = FALSE;
pos_T *top, *bot;
int lnum_in_visual_area = FALSE;
pos_T pos;
long v;
int char_attr = 0;
int attr_pri = FALSE;
int area_highlighting = FALSE;
int attr = 0;
int area_attr = 0;
int search_attr = 0;
#ifdef FEAT_SYN_HL
int vcol_save_attr = 0;
int syntax_attr = 0;
int has_syntax = FALSE;
int save_did_emsg;
int eol_hl_off = 0;
int draw_color_col = FALSE;
int *color_cols = NULL;
#endif
#ifdef FEAT_SPELL
int has_spell = FALSE;
# define SPWORDLEN 150
char_u nextline[SPWORDLEN * 2];
int nextlinecol = 0;
int nextline_idx = 0;
int spell_attr = 0;
int word_end = 0;
static linenr_T checked_lnum = 0;
static int checked_col = 0;
static int cap_col = -1;
static linenr_T capcol_lnum = 0;
int cur_checked_col = 0;
#endif
int extra_check;
#ifdef FEAT_MBYTE
int multi_attr = 0;
int mb_l = 1;
int mb_c = 0;
int mb_utf8 = FALSE;
int u8cc[MAX_MCO];
#endif
#ifdef FEAT_DIFF
int filler_lines;
int filler_todo;
hlf_T diff_hlf = (hlf_T)0;
int change_start = MAXCOL;
int change_end = -1;
#endif
colnr_T trailcol = MAXCOL;
#ifdef FEAT_LINEBREAK
int need_showbreak = FALSE;
#endif
#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
|| defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
# define LINE_ATTR
int line_attr = 0;
#endif
#ifdef FEAT_SEARCH_EXTRA
matchitem_T *cur;
match_T *shl;
int shl_flag;
int pos_inprogress;
int prevcol_hl_flag;
#endif
#ifdef FEAT_ARABIC
int prev_c = 0;
int prev_c1 = 0;
#endif
#if defined(LINE_ATTR)
int did_line_attr = 0;
#endif
#ifdef FEAT_TERMINAL
int get_term_attr = FALSE;
int term_attr = 0;
#endif
#define WL_START 0
#ifdef FEAT_CMDWIN
# define WL_CMDLINE WL_START + 1
#else
# define WL_CMDLINE WL_START
#endif
#ifdef FEAT_FOLDING
# define WL_FOLD WL_CMDLINE + 1
#else
# define WL_FOLD WL_CMDLINE
#endif
#ifdef FEAT_SIGNS
# define WL_SIGN WL_FOLD + 1
#else
# define WL_SIGN WL_FOLD
#endif
#define WL_NR WL_SIGN + 1
#ifdef FEAT_LINEBREAK
# define WL_BRI WL_NR + 1
#else
# define WL_BRI WL_NR
#endif
#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
# define WL_SBR WL_BRI + 1
#else
# define WL_SBR WL_BRI
#endif
#define WL_LINE WL_SBR + 1
int draw_state = WL_START;
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
int feedback_col = 0;
int feedback_old_attr = -1;
#endif
#ifdef FEAT_CONCEAL
int syntax_flags = 0;
int syntax_seqnr = 0;
int prev_syntax_id = 0;
int conceal_attr = HL_ATTR(HLF_CONCEAL);
int is_concealing = FALSE;
int boguscols = 0;
int vcol_off = 0;
int did_wcol = FALSE;
int match_conc = 0;
int has_match_conc = 0;
int old_boguscols = 0;
# define VCOL_HLC (vcol - vcol_off)
# define FIX_FOR_BOGUSCOLS \
{ \
n_extra += vcol_off; \
vcol -= vcol_off; \
vcol_off = 0; \
col -= boguscols; \
old_boguscols = boguscols; \
boguscols = 0; \
}
#else
# define VCOL_HLC (vcol)
#endif
if (startrow > endrow)
return startrow;
row = startrow;
screen_row = row + W_WINROW(wp);
#ifdef FEAT_LINEBREAK
extra_check = wp->w_p_lbr;
#else
extra_check = 0;
#endif
#ifdef FEAT_SYN_HL
if (syntax_present(wp) && !wp->w_s->b_syn_error
# ifdef SYN_TIME_LIMIT
&& !wp->w_s->b_syn_slow
# endif
)
{
save_did_emsg = did_emsg;
did_emsg = FALSE;
syntax_start(wp, lnum);
if (did_emsg)
wp->w_s->b_syn_error = TRUE;
else
{
did_emsg = save_did_emsg;
#ifdef SYN_TIME_LIMIT
if (!wp->w_s->b_syn_slow)
#endif
{
has_syntax = TRUE;
extra_check = TRUE;
}
}
}
color_cols = wp->w_p_cc_cols;
if (color_cols != NULL)
draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
#endif
#ifdef FEAT_TERMINAL
if (term_show_buffer(wp->w_buffer))
{
extra_check = TRUE;
get_term_attr = TRUE;
term_attr = term_get_attr(wp->w_buffer, lnum, -1);
}
#endif
#ifdef FEAT_SPELL
if (wp->w_p_spell
&& *wp->w_s->b_p_spl != NUL
&& wp->w_s->b_langp.ga_len > 0
&& *(char **)(wp->w_s->b_langp.ga_data) != NULL)
{
has_spell = TRUE;
extra_check = TRUE;
nextline[SPWORDLEN] = NUL;
if (lnum < wp->w_buffer->b_ml.ml_line_count)
{
line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
}
if (lnum == checked_lnum)
cur_checked_col = checked_col;
checked_lnum = 0;
if (lnum != capcol_lnum)
cap_col = -1;
if (lnum == 1)
cap_col = 0;
capcol_lnum = 0;
}
#endif
fromcol = -10;
tocol = MAXCOL;
if (VIsual_active && wp->w_buffer == curwin->w_buffer)
{
if (LTOREQ_POS(curwin->w_cursor, VIsual))
{
top = &curwin->w_cursor;
bot = &VIsual;
}
else
{
top = &VIsual;
bot = &curwin->w_cursor;
}
lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
if (VIsual_mode == Ctrl_V)
{
if (lnum_in_visual_area)
{
fromcol = wp->w_old_cursor_fcol;
tocol = wp->w_old_cursor_lcol;
}
}
else
{
if (lnum > top->lnum && lnum <= bot->lnum)
fromcol = 0;
else if (lnum == top->lnum)
{
if (VIsual_mode == 'V')
fromcol = 0;
else
{
getvvcol(wp, top, (colnr_T *)&fromcol, NULL, NULL);
if (gchar_pos(top) == NUL)
tocol = fromcol + 1;
}
}
if (VIsual_mode != 'V' && lnum == bot->lnum)
{
if (*p_sel == 'e' && bot->col == 0
#ifdef FEAT_VIRTUALEDIT
&& bot->coladd == 0
#endif
)
{
fromcol = -10;
tocol = MAXCOL;
}
else if (bot->col == MAXCOL)
tocol = MAXCOL;
else
{
pos = *bot;
if (*p_sel == 'e')
getvvcol(wp, &pos, (colnr_T *)&tocol, NULL, NULL);
else
{
getvvcol(wp, &pos, NULL, NULL, (colnr_T *)&tocol);
++tocol;
}
}
}
}
if (!highlight_match && lnum == curwin->w_cursor.lnum && wp == curwin
#ifdef FEAT_GUI
&& !gui.in_use
#endif
)
noinvcur = TRUE;
if (fromcol >= 0)
{
area_highlighting = TRUE;
attr = HL_ATTR(HLF_V);
#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
if ((clip_star.available && !clip_star.owned
&& clip_isautosel_star())
|| (clip_plus.available && !clip_plus.owned
&& clip_isautosel_plus()))
attr = HL_ATTR(HLF_VNC);
#endif
}
}
else if (highlight_match
&& wp == curwin
&& lnum >= curwin->w_cursor.lnum
&& lnum <= curwin->w_cursor.lnum + search_match_lines)
{
if (lnum == curwin->w_cursor.lnum)
getvcol(curwin, &(curwin->w_cursor),
(colnr_T *)&fromcol, NULL, NULL);
else
fromcol = 0;
if (lnum == curwin->w_cursor.lnum + search_match_lines)
{
pos.lnum = lnum;
pos.col = search_match_endcol;
getvcol(curwin, &pos, (colnr_T *)&tocol, NULL, NULL);
}
else
tocol = MAXCOL;
if (fromcol == tocol)
tocol = fromcol + 1;
area_highlighting = TRUE;
attr = HL_ATTR(HLF_I);
}
#ifdef FEAT_DIFF
filler_lines = diff_check(wp, lnum);
if (filler_lines < 0)
{
if (filler_lines == -1)
{
if (diff_find_change(wp, lnum, &change_start, &change_end))
diff_hlf = HLF_ADD;
else if (change_start == 0)
diff_hlf = HLF_TXD;
else
diff_hlf = HLF_CHD;
}
else
diff_hlf = HLF_ADD;
filler_lines = 0;
area_highlighting = TRUE;
}
if (lnum == wp->w_topline)
filler_lines = wp->w_topfill;
filler_todo = filler_lines;
#endif
#ifdef LINE_ATTR
# ifdef FEAT_SIGNS
v = buf_getsigntype(wp->w_buffer, lnum, SIGN_LINEHL);
if (v != 0)
line_attr = sign_get_attr((int)v, TRUE);
# endif
# if defined(FEAT_QUICKFIX)
if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
line_attr = HL_ATTR(HLF_QFL);
# endif
if (line_attr != 0)
area_highlighting = TRUE;
#endif
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line;
#ifdef FEAT_SPELL
if (has_spell)
{
if (cap_col == 0)
cap_col = getwhitecols(line);
if (nextline[SPWORDLEN] == NUL)
{
nextlinecol = MAXCOL;
nextline_idx = 0;
}
else
{
v = (long)STRLEN(line);
if (v < SPWORDLEN)
{
nextlinecol = 0;
mch_memmove(nextline, line, (size_t)v);
STRMOVE(nextline + v, nextline + SPWORDLEN);
nextline_idx = v + 1;
}
else
{
nextlinecol = v - SPWORDLEN;
mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
nextline_idx = SPWORDLEN + 1;
}
}
}
#endif
if (wp->w_p_list)
{
if (lcs_space || lcs_trail)
extra_check = TRUE;
if (lcs_trail)
{
trailcol = (colnr_T)STRLEN(ptr);
while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
--trailcol;
trailcol += (colnr_T) (ptr - line);
}
}
if (wp->w_p_wrap)
v = wp->w_skipcol;
else
v = wp->w_leftcol;
if (v > 0)
{
#ifdef FEAT_MBYTE
char_u *prev_ptr = ptr;
#endif
while (vcol < v && *ptr != NUL)
{
c = win_lbr_chartabsize(wp, line, ptr, (colnr_T)vcol, NULL);
vcol += c;
#ifdef FEAT_MBYTE
prev_ptr = ptr;
#endif
MB_PTR_ADV(ptr);
}
if (vcol < v && (
#ifdef FEAT_SYN_HL
wp->w_p_cuc || draw_color_col ||
#endif
#ifdef FEAT_VIRTUALEDIT
virtual_active() ||
#endif
(VIsual_active && wp->w_buffer == curwin->w_buffer)))
{
vcol = v;
}
if (vcol > v)
{
vcol -= c;
#ifdef FEAT_MBYTE
ptr = prev_ptr;
#else
--ptr;
#endif
if ((
#ifdef FEAT_MBYTE
(*mb_ptr2cells)(ptr) >= c ||
#endif
*ptr == TAB) && col == 0)
n_skip = v - vcol;
}
if (tocol <= vcol)
fromcol = 0;
else if (fromcol >= 0 && fromcol < vcol)
fromcol = vcol;
#ifdef FEAT_LINEBREAK
if (wp->w_p_wrap)
need_showbreak = TRUE;
#endif
#ifdef FEAT_SPELL
if (has_spell)
{
int len;
colnr_T linecol = (colnr_T)(ptr - line);
hlf_T spell_hlf = HLF_COUNT;
pos = wp->w_cursor;
wp->w_cursor.lnum = lnum;
wp->w_cursor.col = linecol;
len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + linecol;
if (len == 0 || (int)wp->w_cursor.col > ptr - line)
{
spell_hlf = HLF_COUNT;
word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
}
else
{
word_end = wp->w_cursor.col + len + 1;
if (spell_hlf != HLF_COUNT)
spell_attr = highlight_attr[spell_hlf];
}
wp->w_cursor = pos;
# ifdef FEAT_SYN_HL
if (has_syntax)
syntax_start(wp, lnum);
# endif
}
#endif
}
if (fromcol >= 0)
{
if (noinvcur)
{
if ((colnr_T)fromcol == wp->w_virtcol)
{
fromcol_prev = fromcol;
fromcol = -1;
}
else if ((colnr_T)fromcol < wp->w_virtcol)
fromcol_prev = wp->w_virtcol;
}
if (fromcol >= tocol)
fromcol = -1;
}
#ifdef FEAT_SEARCH_EXTRA
cur = wp->w_match_head;
shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE)
{
if (shl_flag == FALSE)
{
shl = &search_hl;
shl_flag = TRUE;
}
else
shl = &cur->hl;
shl->startcol = MAXCOL;
shl->endcol = MAXCOL;
shl->attr_cur = 0;
shl->is_addpos = FALSE;
v = (long)(ptr - line);
if (cur != NULL)
cur->pos.cur = 0;
next_search_hl(wp, shl, lnum, (colnr_T)v,
shl == &search_hl ? NULL : cur);
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + v;
if (shl->lnum != 0 && shl->lnum <= lnum)
{
if (shl->lnum == lnum)
shl->startcol = shl->rm.startpos[0].col;
else
shl->startcol = 0;
if (lnum == shl->lnum + shl->rm.endpos[0].lnum
- shl->rm.startpos[0].lnum)
shl->endcol = shl->rm.endpos[0].col;
else
shl->endcol = MAXCOL;
if (shl->startcol == shl->endcol)
{
#ifdef FEAT_MBYTE
if (has_mbyte && line[shl->endcol] != NUL)
shl->endcol += (*mb_ptr2len)(line + shl->endcol);
else
#endif
++shl->endcol;
}
if ((long)shl->startcol < v)
{
shl->attr_cur = shl->attr;
search_attr = shl->attr;
}
area_highlighting = TRUE;
}
if (shl != &search_hl && cur != NULL)
cur = cur->next;
}
#endif
#ifdef FEAT_SYN_HL
if (wp->w_p_cul && lnum == wp->w_cursor.lnum
&& !(wp == curwin && VIsual_active))
{
line_attr = HL_ATTR(HLF_CUL);
area_highlighting = TRUE;
}
#endif
off = (unsigned)(current_ScreenLine - ScreenLines);
col = 0;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
col = wp->w_width - 1;
off += col;
}
#endif
for (;;)
{
#ifdef FEAT_CONCEAL
has_match_conc = 0;
#endif
if (draw_state != WL_LINE)
{
#ifdef FEAT_CMDWIN
if (draw_state == WL_CMDLINE - 1 && n_extra == 0)
{
draw_state = WL_CMDLINE;
if (cmdwin_type != 0 && wp == curwin)
{
n_extra = 1;
c_extra = cmdwin_type;
char_attr = HL_ATTR(HLF_AT);
}
}
#endif
#ifdef FEAT_FOLDING
if (draw_state == WL_FOLD - 1 && n_extra == 0)
{
int fdc = compute_foldcolumn(wp, 0);
draw_state = WL_FOLD;
if (fdc > 0)
{
vim_free(p_extra_free);
p_extra_free = alloc(12 + 1);
if (p_extra_free != NULL)
{
fill_foldcolumn(p_extra_free, wp, FALSE, lnum);
n_extra = fdc;
p_extra_free[n_extra] = NUL;
p_extra = p_extra_free;
c_extra = NUL;
char_attr = HL_ATTR(HLF_FC);
}
}
}
#endif
#ifdef FEAT_SIGNS
if (draw_state == WL_SIGN - 1 && n_extra == 0)
{
draw_state = WL_SIGN;
if (signcolumn_on(wp))
{
int text_sign;
# ifdef FEAT_SIGN_ICONS
int icon_sign;
# endif
c_extra = ' ';
char_attr = HL_ATTR(HLF_SC);
n_extra = 2;
if (row == startrow
#ifdef FEAT_DIFF
+ filler_lines && filler_todo <= 0
#endif
)
{
text_sign = buf_getsigntype(wp->w_buffer, lnum,
SIGN_TEXT);
# ifdef FEAT_SIGN_ICONS
icon_sign = buf_getsigntype(wp->w_buffer, lnum,
SIGN_ICON);
if (gui.in_use && icon_sign != 0)
{
c_extra = SIGN_BYTE;
# ifdef FEAT_NETBEANS_INTG
if (buf_signcount(wp->w_buffer, lnum) > 1)
c_extra = MULTISIGN_BYTE;
# endif
char_attr = icon_sign;
}
else
# endif
if (text_sign != 0)
{
p_extra = sign_get_text(text_sign);
if (p_extra != NULL)
{
c_extra = NUL;
n_extra = (int)STRLEN(p_extra);
}
char_attr = sign_get_attr(text_sign, FALSE);
}
}
}
}
#endif
if (draw_state == WL_NR - 1 && n_extra == 0)
{
draw_state = WL_NR;
if ((wp->w_p_nu || wp->w_p_rnu)
&& (row == startrow
#ifdef FEAT_DIFF
+ filler_lines
#endif
|| vim_strchr(p_cpo, CPO_NUMCOL) == NULL))
{
if (row == startrow
#ifdef FEAT_DIFF
+ filler_lines
#endif
)
{
long num;
char *fmt = "%*ld ";
if (wp->w_p_nu && !wp->w_p_rnu)
num = (long)lnum;
else
{
num = labs((long)get_cursor_rel_lnum(wp, lnum));
if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
{
num = lnum;
fmt = "%-*ld ";
}
}
sprintf((char *)extra, fmt,
number_width(wp), num);
if (wp->w_skipcol > 0)
for (p_extra = extra; *p_extra == ' '; ++p_extra)
*p_extra = '-';
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
rl_mirror(extra);
#endif
p_extra = extra;
c_extra = NUL;
}
else
c_extra = ' ';
n_extra = number_width(wp) + 1;
char_attr = HL_ATTR(HLF_N);
#ifdef FEAT_SYN_HL
if ((wp->w_p_cul || wp->w_p_rnu)
&& lnum == wp->w_cursor.lnum)
char_attr = HL_ATTR(HLF_CLN);
#endif
}
}
#ifdef FEAT_LINEBREAK
if (wp->w_p_brisbr && draw_state == WL_BRI - 1
&& n_extra == 0 && *p_sbr != NUL)
draw_state = WL_BRI;
else if (wp->w_p_brisbr && draw_state == WL_SBR && n_extra == 0)
draw_state = WL_BRI - 1;
if (draw_state == WL_BRI - 1 && n_extra == 0)
{
draw_state = WL_BRI;
if (wp->w_p_bri && n_extra == 0
&& (row != startrow || need_showbreak)
# ifdef FEAT_DIFF
&& filler_lines == 0
# endif
)
{
char_attr = 0;
# ifdef FEAT_DIFF
if (diff_hlf != (hlf_T)0)
{
char_attr = HL_ATTR(diff_hlf);
# ifdef FEAT_SYN_HL
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
char_attr = hl_combine_attr(char_attr,
HL_ATTR(HLF_CUL));
# endif
}
# endif
p_extra = NULL;
c_extra = ' ';
n_extra = get_breakindent_win(wp,
ml_get_buf(wp->w_buffer, lnum, FALSE));
if (tocol == vcol)
tocol += n_extra;
}
}
#endif
#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
if (draw_state == WL_SBR - 1 && n_extra == 0)
{
draw_state = WL_SBR;
# ifdef FEAT_DIFF
if (filler_todo > 0)
{
if (char2cells(fill_diff) > 1)
c_extra = '-';
else
c_extra = fill_diff;
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
n_extra = col + 1;
else
# endif
n_extra = wp->w_width - col;
char_attr = HL_ATTR(HLF_DED);
}
# endif
# ifdef FEAT_LINEBREAK
if (*p_sbr != NUL && need_showbreak)
{
p_extra = p_sbr;
c_extra = NUL;
n_extra = (int)STRLEN(p_sbr);
char_attr = HL_ATTR(HLF_AT);
need_showbreak = FALSE;
vcol_sbr = vcol + MB_CHARLEN(p_sbr);
if (tocol == vcol)
tocol += n_extra;
#ifdef FEAT_SYN_HL
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
char_attr = hl_combine_attr(char_attr,
HL_ATTR(HLF_CUL));
#endif
}
# endif
}
#endif
if (draw_state == WL_LINE - 1 && n_extra == 0)
{
draw_state = WL_LINE;
if (saved_n_extra)
{
n_extra = saved_n_extra;
c_extra = saved_c_extra;
p_extra = saved_p_extra;
char_attr = saved_char_attr;
}
else
char_attr = 0;
}
}
if (dollar_vcol >= 0 && wp == curwin
&& lnum == wp->w_cursor.lnum && vcol >= (long)wp->w_virtcol
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
)
{
screen_line(screen_row, wp->w_wincol, col, -(int)wp->w_width,
HAS_RIGHTLEFT(wp->w_p_rl));
#ifdef FEAT_SYN_HL
if (wp->w_p_cuc)
row = wp->w_cline_row + wp->w_cline_height;
else
#endif
row = wp->w_height;
break;
}
if (draw_state == WL_LINE && area_highlighting)
{
if (vcol == fromcol
#ifdef FEAT_MBYTE
|| (has_mbyte && vcol + 1 == fromcol && n_extra == 0
&& (*mb_ptr2cells)(ptr) > 1)
#endif
|| ((int)vcol_prev == fromcol_prev
&& vcol_prev < vcol
&& vcol < tocol))
area_attr = attr;
else if (area_attr != 0
&& (vcol == tocol
|| (noinvcur && (colnr_T)vcol == wp->w_virtcol)))
area_attr = 0;
#ifdef FEAT_SEARCH_EXTRA
if (!n_extra)
{
v = (long)(ptr - line);
cur = wp->w_match_head;
shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE)
{
if (shl_flag == FALSE
&& ((cur != NULL
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL))
{
shl = &search_hl;
shl_flag = TRUE;
}
else
shl = &cur->hl;
if (cur != NULL)
cur->pos.cur = 0;
pos_inprogress = TRUE;
while (shl->rm.regprog != NULL
|| (cur != NULL && pos_inprogress))
{
if (shl->startcol != MAXCOL
&& v >= (long)shl->startcol
&& v < (long)shl->endcol)
{
#ifdef FEAT_MBYTE
int tmp_col = v + MB_PTR2LEN(ptr);
if (shl->endcol < tmp_col)
shl->endcol = tmp_col;
#endif
shl->attr_cur = shl->attr;
#ifdef FEAT_CONCEAL
if (cur != NULL && syn_name2id((char_u *)"Conceal")
== cur->hlg_id)
{
has_match_conc =
v == (long)shl->startcol ? 2 : 1;
match_conc = cur->conceal_char;
}
else
has_match_conc = match_conc = 0;
#endif
}
else if (v == (long)shl->endcol)
{
shl->attr_cur = 0;
next_search_hl(wp, shl, lnum, (colnr_T)v,
shl == &search_hl ? NULL : cur);
pos_inprogress = cur == NULL || cur->pos.cur == 0
? FALSE : TRUE;
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + v;
if (shl->lnum == lnum)
{
shl->startcol = shl->rm.startpos[0].col;
if (shl->rm.endpos[0].lnum == 0)
shl->endcol = shl->rm.endpos[0].col;
else
shl->endcol = MAXCOL;
if (shl->startcol == shl->endcol)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
shl->endcol += (*mb_ptr2len)(line
+ shl->endcol);
else
#endif
++shl->endcol;
}
continue;
}
}
break;
}
if (shl != &search_hl && cur != NULL)
cur = cur->next;
}
search_attr = search_hl.attr_cur;
cur = wp->w_match_head;
shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE)
{
if (shl_flag == FALSE
&& ((cur != NULL
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL))
{
shl = &search_hl;
shl_flag = TRUE;
}
else
shl = &cur->hl;
if (shl->attr_cur != 0)
search_attr = shl->attr_cur;
if (shl != &search_hl && cur != NULL)
cur = cur->next;
}
if (*ptr == NUL && (did_line_attr >= 1
|| (wp->w_p_list && lcs_eol_one == -1)))
search_attr = 0;
}
#endif
#ifdef FEAT_DIFF
if (diff_hlf != (hlf_T)0)
{
if (diff_hlf == HLF_CHD && ptr - line >= change_start
&& n_extra == 0)
diff_hlf = HLF_TXD;
if (diff_hlf == HLF_TXD && ptr - line > change_end
&& n_extra == 0)
diff_hlf = HLF_CHD;
line_attr = HL_ATTR(diff_hlf);
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
line_attr = hl_combine_attr(line_attr, HL_ATTR(HLF_CUL));
}
#endif
attr_pri = TRUE;
#ifdef LINE_ATTR
if (area_attr != 0)
char_attr = hl_combine_attr(line_attr, area_attr);
else if (search_attr != 0)
char_attr = hl_combine_attr(line_attr, search_attr);
else if (line_attr != 0 && ((fromcol == -10 && tocol == MAXCOL)
|| vcol < fromcol || vcol_prev < fromcol_prev
|| vcol >= tocol))
char_attr = line_attr;
#else
if (area_attr != 0)
char_attr = area_attr;
else if (search_attr != 0)
char_attr = search_attr;
#endif
else
{
attr_pri = FALSE;
#ifdef FEAT_SYN_HL
if (has_syntax)
char_attr = syntax_attr;
else
#endif
char_attr = 0;
}
}
if (n_extra > 0)
{
if (c_extra != NUL)
{
c = c_extra;
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
}
else
{
c = *p_extra;
#ifdef FEAT_MBYTE
if (has_mbyte)
{
mb_c = c;
if (enc_utf8)
{
mb_l = utfc_ptr2len(p_extra);
mb_utf8 = FALSE;
if (mb_l > n_extra)
mb_l = 1;
else if (mb_l > 1)
{
mb_c = utfc_ptr2char(p_extra, u8cc);
mb_utf8 = TRUE;
c = 0xc0;
}
}
else
{
mb_l = MB_BYTE2LEN(c);
if (mb_l >= n_extra)
mb_l = 1;
else if (mb_l > 1)
mb_c = (c << 8) + p_extra[1];
}
if (mb_l == 0)
mb_l = 1;
if ((
# ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col <= 0) :
# endif
(col >= wp->w_width - 1))
&& (*mb_char2cells)(mb_c) == 2)
{
c = '>';
mb_c = c;
mb_l = 1;
mb_utf8 = FALSE;
multi_attr = HL_ATTR(HLF_AT);
++n_extra;
--p_extra;
}
else
{
n_extra -= mb_l - 1;
p_extra += mb_l - 1;
}
}
#endif
++p_extra;
}
--n_extra;
}
else
{
#ifdef FEAT_LINEBREAK
int c0;
#endif
if (p_extra_free != NULL)
{
vim_free(p_extra_free);
p_extra_free = NULL;
}
c = *ptr;
#ifdef FEAT_LINEBREAK
c0 = *ptr;
#endif
#ifdef FEAT_MBYTE
if (has_mbyte)
{
mb_c = c;
if (enc_utf8)
{
mb_l = utfc_ptr2len(ptr);
mb_utf8 = FALSE;
if (mb_l > 1)
{
mb_c = utfc_ptr2char(ptr, u8cc);
if (mb_c < 0x80)
{
c = mb_c;
# ifdef FEAT_LINEBREAK
c0 = mb_c;
# endif
}
mb_utf8 = TRUE;
if (utf_iscomposing(mb_c))
{
int i;
for (i = Screen_mco - 1; i > 0; --i)
u8cc[i] = u8cc[i - 1];
u8cc[0] = mb_c;
mb_c = ' ';
}
}
if ((mb_l == 1 && c >= 0x80)
|| (mb_l >= 1 && mb_c == 0)
|| (mb_l > 1 && (!vim_isprintc(mb_c)
# ifdef UNICODE16
|| mb_c >= 0x10000
# endif
)))
{
# ifdef UNICODE16
if (mb_c < 0x10000)
# endif
{
transchar_hex(extra, mb_c);
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
rl_mirror(extra);
# endif
}
# ifdef UNICODE16
else if (utf_char2cells(mb_c) != 2)
STRCPY(extra, "?");
else
STRCPY(extra, "\357\274\237");
# endif
p_extra = extra;
c = *p_extra;
mb_c = mb_ptr2char_adv(&p_extra);
mb_utf8 = (c >= 0x80);
n_extra = (int)STRLEN(p_extra);
c_extra = NUL;
if (area_attr == 0 && search_attr == 0)
{
n_attr = n_extra + 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
}
}
else if (mb_l == 0)
mb_l = 1;
#ifdef FEAT_ARABIC
else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
{
int pc, pc1, nc;
int pcc[MAX_MCO];
if (wp->w_p_rl)
{
pc = prev_c;
pc1 = prev_c1;
nc = utf_ptr2char(ptr + mb_l);
prev_c1 = u8cc[0];
}
else
{
pc = utfc_ptr2char(ptr + mb_l, pcc);
nc = prev_c;
pc1 = pcc[0];
}
prev_c = mb_c;
mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
}
else
prev_c = mb_c;
#endif
}
else
{
mb_l = MB_BYTE2LEN(c);
if (mb_l == 0)
mb_l = 1;
else if (mb_l > 1)
{
if (ptr[1] >= 32)
mb_c = (c << 8) + ptr[1];
else
{
if (ptr[1] == NUL)
{
mb_l = 1;
transchar_nonprint(extra, c);
}
else
{
mb_l = 2;
STRCPY(extra, "XX");
}
p_extra = extra;
n_extra = (int)STRLEN(extra) - 1;
c_extra = NUL;
c = *p_extra++;
if (area_attr == 0 && search_attr == 0)
{
n_attr = n_extra + 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
}
mb_c = c;
}
}
}
if ((
# ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col <= 0) :
# endif
(col >= wp->w_width - 1))
&& (*mb_char2cells)(mb_c) == 2)
{
c = '>';
mb_c = c;
mb_utf8 = FALSE;
mb_l = 1;
multi_attr = HL_ATTR(HLF_AT);
--ptr;
}
else if (*ptr != NUL)
ptr += mb_l - 1;
if (n_skip > 0 && mb_l > 1 && n_extra == 0)
{
n_extra = 1;
c_extra = MB_FILLER_CHAR;
c = ' ';
if (area_attr == 0 && search_attr == 0)
{
n_attr = n_extra + 1;
extra_attr = HL_ATTR(HLF_AT);
saved_attr2 = char_attr;
}
mb_c = c;
mb_utf8 = FALSE;
mb_l = 1;
}
}
#endif
++ptr;
if (extra_check)
{
#ifdef FEAT_SPELL
int can_spell = TRUE;
#endif
#ifdef FEAT_TERMINAL
if (get_term_attr)
{
syntax_attr = term_get_attr(wp->w_buffer, lnum, vcol);
if (!attr_pri)
char_attr = syntax_attr;
else
char_attr = hl_combine_attr(syntax_attr, char_attr);
}
#endif
#ifdef FEAT_SYN_HL
v = (long)(ptr - line);
if (has_syntax && v > 0)
{
save_did_emsg = did_emsg;
did_emsg = FALSE;
syntax_attr = get_syntax_attr((colnr_T)v - 1,
# ifdef FEAT_SPELL
has_spell ? &can_spell :
# endif
NULL, FALSE);
if (did_emsg)
{
wp->w_s->b_syn_error = TRUE;
has_syntax = FALSE;
}
else
did_emsg = save_did_emsg;
#ifdef SYN_TIME_LIMIT
if (wp->w_s->b_syn_slow)
has_syntax = FALSE;
#endif
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line + v;
if (!attr_pri)
char_attr = syntax_attr;
else
char_attr = hl_combine_attr(syntax_attr, char_attr);
# ifdef FEAT_CONCEAL
if (c == NUL)
syntax_flags = 0;
else
syntax_flags = get_syntax_info(&syntax_seqnr);
# endif
}
#endif
#ifdef FEAT_SPELL
if (has_spell && v >= word_end && v > cur_checked_col)
{
spell_attr = 0;
# ifdef FEAT_SYN_HL
if (!attr_pri)
char_attr = syntax_attr;
# endif
if (c != 0 && (
# ifdef FEAT_SYN_HL
!has_syntax ||
# endif
can_spell))
{
char_u *prev_ptr, *p;
int len;
hlf_T spell_hlf = HLF_COUNT;
# ifdef FEAT_MBYTE
if (has_mbyte)
{
prev_ptr = ptr - mb_l;
v -= mb_l - 1;
}
else
# endif
prev_ptr = ptr - 1;
if ((prev_ptr - line) - nextlinecol >= 0)
p = nextline + (prev_ptr - line) - nextlinecol;
else
p = prev_ptr;
cap_col -= (int)(prev_ptr - line);
len = spell_check(wp, p, &spell_hlf, &cap_col,
nochange);
word_end = v + len;
if (spell_hlf != HLF_COUNT
&& (State & INSERT) != 0
&& wp->w_cursor.lnum == lnum
&& wp->w_cursor.col >=
(colnr_T)(prev_ptr - line)
&& wp->w_cursor.col < (colnr_T)word_end)
{
spell_hlf = HLF_COUNT;
spell_redraw_lnum = lnum;
}
if (spell_hlf == HLF_COUNT && p != prev_ptr
&& (p - nextline) + len > nextline_idx)
{
checked_lnum = lnum + 1;
checked_col = (int)((p - nextline) + len - nextline_idx);
}
if (spell_hlf != HLF_COUNT)
spell_attr = highlight_attr[spell_hlf];
if (cap_col > 0)
{
if (p != prev_ptr
&& (p - nextline) + cap_col >= nextline_idx)
{
capcol_lnum = lnum + 1;
cap_col = (int)((p - nextline) + cap_col
- nextline_idx);
}
else
cap_col += (int)(prev_ptr - line);
}
}
}
if (spell_attr != 0)
{
if (!attr_pri)
char_attr = hl_combine_attr(char_attr, spell_attr);
else
char_attr = hl_combine_attr(spell_attr, char_attr);
}
#endif
#ifdef FEAT_LINEBREAK
if (wp->w_p_lbr && c0 == c
&& VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
{
# ifdef FEAT_MBYTE
int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1) : 0;
# endif
char_u *p = ptr - (
# ifdef FEAT_MBYTE
mb_off +
# endif
1);
n_extra = win_lbr_chartabsize(wp, line, p, (colnr_T)vcol,
NULL) - 1;
if (c == TAB && n_extra + col > wp->w_width)
n_extra = (int)wp->w_buffer->b_p_ts
- vcol % (int)wp->w_buffer->b_p_ts - 1;
# ifdef FEAT_MBYTE
c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
# else
c_extra = ' ';
# endif
if (VIM_ISWHITE(c))
{
#ifdef FEAT_CONCEAL
if (c == TAB)
FIX_FOR_BOGUSCOLS;
#endif
if (!wp->w_p_list)
c = ' ';
}
}
#endif
if (wp->w_p_list
&& (((c == 160
#ifdef FEAT_MBYTE
|| (mb_utf8 && (mb_c == 160 || mb_c == 0x202f))
#endif
) && lcs_nbsp)
|| (c == ' ' && lcs_space && ptr - line <= trailcol)))
{
c = (c == ' ') ? lcs_space : lcs_nbsp;
if (area_attr == 0 && search_attr == 0)
{
n_attr = 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
}
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
}
if (trailcol != MAXCOL && ptr > line + trailcol && c == ' ')
{
c = lcs_trail;
if (!attr_pri)
{
n_attr = 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
}
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
}
}
if (!vim_isprintc(c))
{
if (c == TAB && (!wp->w_p_list || lcs_tab1))
{
int tab_len = 0;
long vcol_adjusted = vcol;
#ifdef FEAT_LINEBREAK
if (*p_sbr != NUL && vcol == vcol_sbr && wp->w_p_wrap)
vcol_adjusted = vcol - MB_CHARLEN(p_sbr);
#endif
tab_len = (int)wp->w_buffer->b_p_ts
- vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
#ifdef FEAT_LINEBREAK
if (!wp->w_p_lbr || !wp->w_p_list)
#endif
n_extra = tab_len;
#ifdef FEAT_LINEBREAK
else
{
char_u *p;
int len = n_extra;
int i;
int saved_nextra = n_extra;
#ifdef FEAT_CONCEAL
if (vcol_off > 0)
tab_len += vcol_off;
if (wp->w_p_list && lcs_tab1 && old_boguscols > 0
&& n_extra > tab_len)
tab_len += n_extra - tab_len;
#endif
#ifdef FEAT_MBYTE
len = (tab_len * mb_char2len(lcs_tab2));
if (n_extra > 0)
len += n_extra - tab_len;
#endif
c = lcs_tab1;
p = alloc((unsigned)(len + 1));
vim_memset(p, ' ', len);
p[len] = NUL;
vim_free(p_extra_free);
p_extra_free = p;
for (i = 0; i < tab_len; i++)
{
#ifdef FEAT_MBYTE
mb_char2bytes(lcs_tab2, p);
p += mb_char2len(lcs_tab2);
n_extra += mb_char2len(lcs_tab2)
- (saved_nextra > 0 ? 1 : 0);
#else
p[i] = lcs_tab2;
#endif
}
p_extra = p_extra_free;
#ifdef FEAT_CONCEAL
if (vcol_off > 0)
n_extra -= vcol_off;
#endif
}
#endif
#ifdef FEAT_CONCEAL
{
int vc_saved = vcol_off;
FIX_FOR_BOGUSCOLS;
if (n_extra == tab_len + vc_saved && wp->w_p_list
&& lcs_tab1)
tab_len += vc_saved;
}
#endif
#ifdef FEAT_MBYTE
mb_utf8 = FALSE;
#endif
if (wp->w_p_list)
{
c = lcs_tab1;
#ifdef FEAT_LINEBREAK
if (wp->w_p_lbr)
c_extra = NUL;
else
#endif
c_extra = lcs_tab2;
n_attr = tab_len + 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
#endif
}
else
{
c_extra = ' ';
c = ' ';
}
}
else if (c == NUL
&& (wp->w_p_list
|| ((fromcol >= 0 || fromcol_prev >= 0)
&& tocol > vcol
&& VIsual_mode != Ctrl_V
&& (
# ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col >= 0) :
# endif
(col < wp->w_width))
&& !(noinvcur
&& lnum == wp->w_cursor.lnum
&& (colnr_T)vcol == wp->w_virtcol)))
&& lcs_eol_one > 0)
{
#if defined(FEAT_DIFF) || defined(LINE_ATTR)
if (
# ifdef FEAT_DIFF
diff_hlf == (hlf_T)0
# ifdef LINE_ATTR
&&
# endif
# endif
# ifdef LINE_ATTR
line_attr == 0
# endif
)
#endif
{
#ifdef FEAT_VIRTUALEDIT
if (area_highlighting && virtual_active()
&& tocol != MAXCOL && vcol < tocol)
n_extra = 0;
else
#endif
{
p_extra = at_end_str;
n_extra = 1;
c_extra = NUL;
}
}
if (wp->w_p_list && lcs_eol > 0)
c = lcs_eol;
else
c = ' ';
lcs_eol_one = -1;
--ptr;
if (!attr_pri)
{
extra_attr = HL_ATTR(HLF_AT);
n_attr = 1;
}
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
}
else if (c != NUL)
{
p_extra = transchar(c);
if (n_extra == 0)
n_extra = byte2cells(c) - 1;
#ifdef FEAT_RIGHTLEFT
if ((dy_flags & DY_UHEX) && wp->w_p_rl)
rl_mirror(p_extra);
#endif
c_extra = NUL;
#ifdef FEAT_LINEBREAK
if (wp->w_p_lbr)
{
char_u *p;
c = *p_extra;
p = alloc((unsigned)n_extra + 1);
vim_memset(p, ' ', n_extra);
STRNCPY(p, p_extra + 1, STRLEN(p_extra) - 1);
p[n_extra] = NUL;
vim_free(p_extra_free);
p_extra_free = p_extra = p;
}
else
#endif
{
n_extra = byte2cells(c) - 1;
c = *p_extra++;
}
if (!attr_pri)
{
n_attr = n_extra + 1;
extra_attr = HL_ATTR(HLF_8);
saved_attr2 = char_attr;
}
#ifdef FEAT_MBYTE
mb_utf8 = FALSE;
#endif
}
#ifdef FEAT_VIRTUALEDIT
else if (VIsual_active
&& (VIsual_mode == Ctrl_V
|| VIsual_mode == 'v')
&& virtual_active()
&& tocol != MAXCOL
&& vcol < tocol
&& (
# ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col >= 0) :
# endif
(col < wp->w_width)))
{
c = ' ';
--ptr;
}
#endif
#if defined(LINE_ATTR)
else if ((
# ifdef FEAT_DIFF
diff_hlf != (hlf_T)0 ||
# endif
# ifdef FEAT_TERMINAL
term_attr != 0 ||
# endif
line_attr != 0
) && (
# ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col >= 0) :
# endif
(col
# ifdef FEAT_CONCEAL
- boguscols
# endif
< wp->w_width)))
{
c = ' ';
--ptr;
++did_line_attr;
if (line_attr != 0 && char_attr == search_attr
&& (did_line_attr > 1
|| (wp->w_p_list && lcs_eol > 0)))
char_attr = line_attr;
# ifdef FEAT_DIFF
if (diff_hlf == HLF_TXD)
{
diff_hlf = HLF_CHD;
if (attr == 0 || char_attr != attr)
{
char_attr = HL_ATTR(diff_hlf);
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
char_attr = hl_combine_attr(char_attr,
HL_ATTR(HLF_CUL));
}
}
# endif
# ifdef FEAT_TERMINAL
if (term_attr != 0)
{
char_attr = term_attr;
if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
char_attr = hl_combine_attr(char_attr,
HL_ATTR(HLF_CUL));
}
# endif
}
#endif
}
#ifdef FEAT_CONCEAL
if ( wp->w_p_cole > 0
&& (wp != curwin || lnum != wp->w_cursor.lnum ||
conceal_cursor_line(wp) )
&& ( (syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
&& !(lnum_in_visual_area
&& vim_strchr(wp->w_p_cocu, 'v') == NULL))
{
char_attr = conceal_attr;
if ((prev_syntax_id != syntax_seqnr || has_match_conc > 1)
&& (syn_get_sub_char() != NUL || match_conc
|| wp->w_p_cole == 1)
&& wp->w_p_cole != 3)
{
if (match_conc)
c = match_conc;
else if (syn_get_sub_char() != NUL)
c = syn_get_sub_char();
else if (lcs_conceal != NUL)
c = lcs_conceal;
else
c = ' ';
prev_syntax_id = syntax_seqnr;
if (n_extra > 0)
vcol_off += n_extra;
vcol += n_extra;
if (wp->w_p_wrap && n_extra > 0)
{
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
col -= n_extra;
boguscols -= n_extra;
}
else
# endif
{
boguscols += n_extra;
col += n_extra;
}
}
n_extra = 0;
n_attr = 0;
}
else if (n_skip == 0)
{
is_concealing = TRUE;
n_skip = 1;
}
# ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
# endif
}
else
{
prev_syntax_id = 0;
is_concealing = FALSE;
}
#endif
}
#ifdef FEAT_CONCEAL
if (!did_wcol && draw_state == WL_LINE
&& wp == curwin && lnum == wp->w_cursor.lnum
&& conceal_cursor_line(wp)
&& (int)wp->w_virtcol <= vcol + n_skip)
{
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
wp->w_wcol = wp->w_width - col + boguscols - 1;
else
# endif
wp->w_wcol = col - boguscols;
wp->w_wrow = row;
did_wcol = TRUE;
}
#endif
if (n_attr > 0
&& draw_state == WL_LINE
&& !attr_pri)
char_attr = extra_attr;
#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
if (p_imst == IM_ON_THE_SPOT
&& xic != NULL
&& lnum == wp->w_cursor.lnum
&& (State & INSERT)
&& !p_imdisable
&& im_is_preediting()
&& draw_state == WL_LINE)
{
colnr_T tcol;
if (preedit_end_col == MAXCOL)
getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
else
tcol = preedit_end_col;
if ((long)preedit_start_col <= vcol && vcol < (long)tcol)
{
if (feedback_old_attr < 0)
{
feedback_col = 0;
feedback_old_attr = char_attr;
}
char_attr = im_get_feedback_attr(feedback_col);
if (char_attr < 0)
char_attr = feedback_old_attr;
feedback_col++;
}
else if (feedback_old_attr >= 0)
{
char_attr = feedback_old_attr;
feedback_old_attr = -1;
feedback_col = 0;
}
}
#endif
if (lcs_prec_todo != NUL
&& wp->w_p_list
&& (wp->w_p_wrap ? wp->w_skipcol > 0 : wp->w_leftcol > 0)
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
&& draw_state > WL_NR
&& c != NUL)
{
c = lcs_prec;
lcs_prec_todo = NUL;
#ifdef FEAT_MBYTE
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
{
c_extra = MB_FILLER_CHAR;
n_extra = 1;
n_attr = 2;
extra_attr = HL_ATTR(HLF_AT);
}
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
if (!attr_pri)
{
saved_attr3 = char_attr;
char_attr = HL_ATTR(HLF_AT);
n_attr3 = 1;
}
}
if (c == NUL
#if defined(LINE_ATTR)
|| did_line_attr == 1
#endif
)
{
#ifdef FEAT_SEARCH_EXTRA
long prevcol = (long)(ptr - line) - (c == NUL);
if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
++prevcol;
#endif
#ifdef FEAT_SEARCH_EXTRA
prevcol_hl_flag = FALSE;
if (!search_hl.is_addpos && prevcol == (long)search_hl.startcol)
prevcol_hl_flag = TRUE;
else
{
cur = wp->w_match_head;
while (cur != NULL)
{
if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol)
{
prevcol_hl_flag = TRUE;
break;
}
cur = cur->next;
}
}
#endif
if (lcs_eol == lcs_eol_one
&& ((area_attr != 0 && vcol == fromcol
&& (VIsual_mode != Ctrl_V
|| lnum == VIsual.lnum
|| lnum == curwin->w_cursor.lnum)
&& c == NUL)
#ifdef FEAT_SEARCH_EXTRA
|| (prevcol_hl_flag == TRUE
# ifdef FEAT_SYN_HL
&& !(wp->w_p_cul && lnum == wp->w_cursor.lnum
&& !(wp == curwin && VIsual_active))
# endif
# ifdef FEAT_DIFF
&& diff_hlf == (hlf_T)0
# endif
# if defined(LINE_ATTR)
&& did_line_attr <= 1
# endif
)
#endif
))
{
int n = 0;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
if (col < 0)
n = 1;
}
else
#endif
{
if (col >= wp->w_width)
n = -1;
}
if (n != 0)
{
off += n;
col += n;
}
else
{
ScreenLines[off] = ' ';
#ifdef FEAT_MBYTE
if (enc_utf8)
ScreenLinesUC[off] = 0;
#endif
}
#ifdef FEAT_SEARCH_EXTRA
if (area_attr == 0)
{
char_attr = search_hl.attr;
cur = wp->w_match_head;
shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE)
{
if (shl_flag == FALSE
&& ((cur != NULL
&& cur->priority > SEARCH_HL_PRIORITY)
|| cur == NULL))
{
shl = &search_hl;
shl_flag = TRUE;
}
else
shl = &cur->hl;
if ((ptr - line) - 1 == (long)shl->startcol
&& (shl == &search_hl || !shl->is_addpos))
char_attr = shl->attr;
if (shl != &search_hl && cur != NULL)
cur = cur->next;
}
}
#endif
ScreenAttrs[off] = char_attr;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
--col;
--off;
}
else
#endif
{
++col;
++off;
}
++vcol;
#ifdef FEAT_SYN_HL
eol_hl_off = 1;
#endif
}
}
if (c == NUL)
{
#ifdef FEAT_SYN_HL
if (eol_hl_off > 0 && vcol - eol_hl_off == (long)wp->w_virtcol
&& lnum == wp->w_cursor.lnum)
{
--col;
--off;
--vcol;
}
if (wp->w_p_wrap)
v = wp->w_skipcol;
else
v = wp->w_leftcol;
if (vcol < v + col - win_col_off(wp))
vcol = v + col - win_col_off(wp);
#ifdef FEAT_CONCEAL
col -= boguscols;
boguscols = 0;
#endif
if (draw_color_col)
draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
if (((wp->w_p_cuc
&& (int)wp->w_virtcol >= VCOL_HLC - eol_hl_off
&& (int)wp->w_virtcol <
wp->w_width * (row - startrow + 1) + v
&& lnum != wp->w_cursor.lnum)
|| draw_color_col)
# ifdef FEAT_RIGHTLEFT
&& !wp->w_p_rl
# endif
)
{
int rightmost_vcol = 0;
int i;
if (wp->w_p_cuc)
rightmost_vcol = wp->w_virtcol;
if (draw_color_col)
for (i = 0; color_cols[i] >= 0; ++i)
if (rightmost_vcol < color_cols[i])
rightmost_vcol = color_cols[i];
while (col < wp->w_width)
{
ScreenLines[off] = ' ';
#ifdef FEAT_MBYTE
if (enc_utf8)
ScreenLinesUC[off] = 0;
#endif
++col;
if (draw_color_col)
draw_color_col = advance_color_col(VCOL_HLC,
&color_cols);
if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol)
ScreenAttrs[off++] = HL_ATTR(HLF_CUC);
else if (draw_color_col && VCOL_HLC == *color_cols)
ScreenAttrs[off++] = HL_ATTR(HLF_MC);
else
ScreenAttrs[off++] = 0;
if (VCOL_HLC >= rightmost_vcol)
break;
++vcol;
}
}
#endif
screen_line(screen_row, wp->w_wincol, col,
(int)wp->w_width, HAS_RIGHTLEFT(wp->w_p_rl));
row++;
if (wp == curwin && lnum == curwin->w_cursor.lnum)
{
curwin->w_cline_row = startrow;
curwin->w_cline_height = row - startrow;
#ifdef FEAT_FOLDING
curwin->w_cline_folded = FALSE;
#endif
curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
}
break;
}
if (lcs_ext
&& !wp->w_p_wrap
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
&& (
#ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? col == 0 :
#endif
col == wp->w_width - 1)
&& (*ptr != NUL
|| (wp->w_p_list && lcs_eol_one > 0)
|| (n_extra && (c_extra != NUL || *p_extra != NUL))))
{
c = lcs_ext;
char_attr = HL_ATTR(HLF_AT);
#ifdef FEAT_MBYTE
mb_c = c;
if (enc_utf8 && utf_char2len(c) > 1)
{
mb_utf8 = TRUE;
u8cc[0] = 0;
c = 0xc0;
}
else
mb_utf8 = FALSE;
#endif
}
#ifdef FEAT_SYN_HL
if (draw_color_col)
draw_color_col = advance_color_col(VCOL_HLC, &color_cols);
vcol_save_attr = -1;
if (draw_state == WL_LINE && !lnum_in_visual_area
&& search_attr == 0 && area_attr == 0)
{
if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
&& lnum != wp->w_cursor.lnum)
{
vcol_save_attr = char_attr;
char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_CUC));
}
else if (draw_color_col && VCOL_HLC == *color_cols)
{
vcol_save_attr = char_attr;
char_attr = hl_combine_attr(char_attr, HL_ATTR(HLF_MC));
}
}
#endif
vcol_prev = vcol;
if (draw_state < WL_LINE || n_skip <= 0)
{
#if defined(FEAT_RIGHTLEFT) && defined(FEAT_MBYTE)
if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
{
--off;
--col;
}
#endif
ScreenLines[off] = c;
#ifdef FEAT_MBYTE
if (enc_dbcs == DBCS_JPNU)
{
if ((mb_c & 0xff00) == 0x8e00)
ScreenLines[off] = 0x8e;
ScreenLines2[off] = mb_c & 0xff;
}
else if (enc_utf8)
{
if (mb_utf8)
{
int i;
ScreenLinesUC[off] = mb_c;
if ((c & 0xff) == 0)
ScreenLines[off] = 0x80;
for (i = 0; i < Screen_mco; ++i)
{
ScreenLinesC[i][off] = u8cc[i];
if (u8cc[i] == 0)
break;
}
}
else
ScreenLinesUC[off] = 0;
}
if (multi_attr)
{
ScreenAttrs[off] = multi_attr;
multi_attr = 0;
}
else
#endif
ScreenAttrs[off] = char_attr;
#ifdef FEAT_MBYTE
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
{
++off;
++col;
if (enc_utf8)
ScreenLines[off] = 0;
else
ScreenLines[off] = mb_c & 0xff;
if (draw_state > WL_NR
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
)
++vcol;
if (tocol == vcol)
++tocol;
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
--off;
--col;
}
#endif
}
#endif
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
--off;
--col;
}
else
#endif
{
++off;
++col;
}
}
#ifdef FEAT_CONCEAL
else if (wp->w_p_cole > 0 && is_concealing)
{
--n_skip;
++vcol_off;
if (n_extra > 0)
vcol_off += n_extra;
if (wp->w_p_wrap)
{
if (n_extra > 0)
{
vcol += n_extra;
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
col -= n_extra;
boguscols -= n_extra;
}
else
# endif
{
col += n_extra;
boguscols += n_extra;
}
n_extra = 0;
n_attr = 0;
}
# ifdef FEAT_MBYTE
if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
{
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
--boguscols;
--col;
}
else
# endif
{
++boguscols;
++col;
}
}
# endif
# ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
--boguscols;
--col;
}
else
# endif
{
++boguscols;
++col;
}
}
else
{
if (n_extra > 0)
{
vcol += n_extra;
n_extra = 0;
n_attr = 0;
}
}
}
#endif
else
--n_skip;
if (draw_state > WL_NR
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
)
++vcol;
#ifdef FEAT_SYN_HL
if (vcol_save_attr >= 0)
char_attr = vcol_save_attr;
#endif
if (draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
char_attr = saved_attr3;
if (n_attr > 0 && draw_state == WL_LINE && --n_attr == 0)
char_attr = saved_attr2;
if ((
#ifdef FEAT_RIGHTLEFT
wp->w_p_rl ? (col < 0) :
#endif
(col >= wp->w_width))
&& (*ptr != NUL
#ifdef FEAT_DIFF
|| filler_todo > 0
#endif
|| (wp->w_p_list && lcs_eol != NUL && p_extra != at_end_str)
|| (n_extra != 0 && (c_extra != NUL || *p_extra != NUL)))
)
{
#ifdef FEAT_CONCEAL
screen_line(screen_row, wp->w_wincol, col - boguscols,
(int)wp->w_width, HAS_RIGHTLEFT(wp->w_p_rl));
boguscols = 0;
#else
screen_line(screen_row, wp->w_wincol, col,
(int)wp->w_width, HAS_RIGHTLEFT(wp->w_p_rl));
#endif
++row;
++screen_row;
if ((!wp->w_p_wrap
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
) || lcs_eol_one == -1)
break;
if (draw_state != WL_LINE
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
)
{
win_draw_end(wp, '@', ' ', row, wp->w_height, HLF_AT);
draw_vsep_win(wp, row);
row = endrow;
}
if (row == endrow)
{
++row;
break;
}
if (screen_cur_row == screen_row - 1
#ifdef FEAT_DIFF
&& filler_todo <= 0
#endif
&& wp->w_width == Columns)
{
LineWraps[screen_row - 1] = TRUE;
if (p_tf
#ifdef FEAT_GUI
&& !gui.in_use
#endif
#ifdef FEAT_MBYTE
&& !(has_mbyte
&& ((*mb_off2cells)(LineOffset[screen_row],
LineOffset[screen_row] + screen_Columns)
== 2
|| (*mb_off2cells)(LineOffset[screen_row - 1]
+ (int)Columns - 2,
LineOffset[screen_row] + screen_Columns)
== 2))
#endif
)
{
if (screen_cur_col != wp->w_width)
screen_char(LineOffset[screen_row - 1]
+ (unsigned)Columns - 1,
screen_row - 1, (int)(Columns - 1));
#ifdef FEAT_MBYTE
if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
screen_row - 1] + (Columns - 1)]) > 1)
out_char(' ');
else
#endif
out_char(ScreenLines[LineOffset[screen_row - 1]
+ (Columns - 1)]);
ScreenAttrs[LineOffset[screen_row]] = (sattr_T)-1;
screen_start();
}
}
col = 0;
off = (unsigned)(current_ScreenLine - ScreenLines);
#ifdef FEAT_RIGHTLEFT
if (wp->w_p_rl)
{
col = wp->w_width - 1;
off += col;
}
#endif
draw_state = WL_START;
saved_n_extra = n_extra;
saved_p_extra = p_extra;
saved_c_extra = c_extra;
saved_char_attr = char_attr;
n_extra = 0;
lcs_prec_todo = lcs_prec;
#ifdef FEAT_LINEBREAK
# ifdef FEAT_DIFF
if (filler_todo <= 0)
# endif
need_showbreak = TRUE;
#endif
#ifdef FEAT_DIFF
--filler_todo;
if (filler_todo == 0 && wp->w_botfill)
break;
#endif
}
}
#ifdef FEAT_SPELL
if (*skipwhite(line) == NUL)
{
capcol_lnum = lnum + 1;
cap_col = 0;
}
#endif
vim_free(p_extra_free);
return row;
}
#ifdef FEAT_MBYTE
static int comp_char_differs(int, int);
static int
comp_char_differs(int off_from, int off_to)
{
int i;
for (i = 0; i < Screen_mco; ++i)
{
if (ScreenLinesC[i][off_from] != ScreenLinesC[i][off_to])
return TRUE;
if (ScreenLinesC[i][off_from] == 0)
break;
}
return FALSE;
}
#endif
static int
char_needs_redraw(int off_from, int off_to, int cols)
{
if (cols > 0
&& ((ScreenLines[off_from] != ScreenLines[off_to]
|| ScreenAttrs[off_from] != ScreenAttrs[off_to])
#ifdef FEAT_MBYTE
|| (enc_dbcs != 0
&& MB_BYTE2LEN(ScreenLines[off_from]) > 1
&& (enc_dbcs == DBCS_JPNU && ScreenLines[off_from] == 0x8e
? ScreenLines2[off_from] != ScreenLines2[off_to]
: (cols > 1 && ScreenLines[off_from + 1]
!= ScreenLines[off_to + 1])))
|| (enc_utf8
&& (ScreenLinesUC[off_from] != ScreenLinesUC[off_to]
|| (ScreenLinesUC[off_from] != 0
&& comp_char_differs(off_from, off_to))
|| ((*mb_off2cells)(off_from, off_from + cols) > 1
&& ScreenLines[off_from + 1]
!= ScreenLines[off_to + 1])))
#endif
))
return TRUE;
return FALSE;
}
#if defined(FEAT_TERMINAL) || defined(PROTO)
int
screen_get_current_line_off()
{
return (int)(current_ScreenLine - ScreenLines);
}
#endif
void
screen_line(
int row,
int coloff,
int endcol,
int clear_width,
int rlflag UNUSED)
{
unsigned off_from;
unsigned off_to;
#ifdef FEAT_MBYTE
unsigned max_off_from;
unsigned max_off_to;
#endif
int col = 0;
int hl;
int force = FALSE;
int redraw_this
#ifdef FEAT_GUI
= TRUE
#endif
;
int redraw_next;
#ifdef FEAT_MBYTE
int clear_next = FALSE;
int char_cells;
# define CHAR_CELLS char_cells
#else
# define CHAR_CELLS 1
#endif
if (row >= Rows)
row = Rows - 1;
if (endcol > Columns)
endcol = Columns;
# ifdef FEAT_CLIPBOARD
clip_may_clear_selection(row, row);
# endif
off_from = (unsigned)(current_ScreenLine - ScreenLines);
off_to = LineOffset[row] + coloff;
#ifdef FEAT_MBYTE
max_off_from = off_from + screen_Columns;
max_off_to = LineOffset[row] + screen_Columns;
#endif
#ifdef FEAT_RIGHTLEFT
if (rlflag)
{
if (clear_width > 0)
{
while (col <= endcol && ScreenLines[off_to] == ' '
&& ScreenAttrs[off_to] == 0
# ifdef FEAT_MBYTE
&& (!enc_utf8 || ScreenLinesUC[off_to] == 0)
# endif
)
{
++off_to;
++col;
}
if (col <= endcol)
screen_fill(row, row + 1, col + coloff,
endcol + coloff + 1, ' ', ' ', 0);
}
col = endcol + 1;
off_to = LineOffset[row] + col + coloff;
off_from += col;
endcol = (clear_width > 0 ? clear_width : -clear_width);
}
#endif
redraw_next = char_needs_redraw(off_from, off_to, endcol - col);
while (col < endcol)
{
#ifdef FEAT_MBYTE
if (has_mbyte && (col + 1 < endcol))
char_cells = (*mb_off2cells)(off_from, max_off_from);
else
char_cells = 1;
#endif
redraw_this = redraw_next;
redraw_next = force || char_needs_redraw(off_from + CHAR_CELLS,
off_to + CHAR_CELLS, endcol - col - CHAR_CELLS);
#ifdef FEAT_GUI
if (redraw_next && gui.in_use)
{
hl = ScreenAttrs[off_to + CHAR_CELLS];
if (hl > HL_ALL)
hl = syn_attr2attr(hl);
if (hl & HL_BOLD)
redraw_this = TRUE;
}
#endif
if (redraw_this)
{
if ( p_wiv
&& !force
#ifdef FEAT_GUI
&& !gui.in_use
#endif
&& ScreenAttrs[off_to] != 0
&& ScreenAttrs[off_from] != ScreenAttrs[off_to])
{
windgoto(row, col + coloff);
out_str(T_CE);
screen_start();
force = TRUE;
redraw_next = TRUE;
if (col + coloff > 0 && ScreenAttrs[off_to - 1] != 0)
{
screen_attr = ScreenAttrs[off_to - 1];
term_windgoto(row, col + coloff);
screen_stop_highlight();
}
else
screen_attr = 0;
}
#ifdef FEAT_MBYTE
if (enc_dbcs != 0)
{
if (char_cells == 1
&& col + 1 < endcol
&& (*mb_off2cells)(off_to, max_off_to) > 1)
{
ScreenLines[off_to + 1] = 0;
redraw_next = TRUE;
}
else if (char_cells == 2
&& col + 2 < endcol
&& (*mb_off2cells)(off_to, max_off_to) == 1
&& (*mb_off2cells)(off_to + 1, max_off_to) > 1)
{
ScreenLines[off_to + 2] = 0;
redraw_next = TRUE;
}
if (enc_dbcs == DBCS_JPNU)
ScreenLines2[off_to] = ScreenLines2[off_from];
}
if (has_mbyte && col + char_cells == endcol
&& ((char_cells == 1
&& (*mb_off2cells)(off_to, max_off_to) > 1)
|| (char_cells == 2
&& (*mb_off2cells)(off_to, max_off_to) == 1
&& (*mb_off2cells)(off_to + 1, max_off_to) > 1)))
clear_next = TRUE;
#endif
ScreenLines[off_to] = ScreenLines[off_from];
#ifdef FEAT_MBYTE
if (enc_utf8)
{
ScreenLinesUC[off_to] = ScreenLinesUC[off_from];
if (ScreenLinesUC[off_from] != 0)
{
int i;
for (i = 0; i < Screen_mco; ++i)
ScreenLinesC[i][off_to] = ScreenLinesC[i][off_from];
}
}
if (char_cells == 2)
ScreenLines[off_to + 1] = ScreenLines[off_from + 1];
#endif
#if defined(FEAT_GUI) || defined(UNIX)
if (
# ifdef FEAT_GUI
gui.in_use
# endif
# if defined(FEAT_GUI) && defined(UNIX)
||
# endif
# ifdef UNIX
term_is_xterm
# endif
)
{
hl = ScreenAttrs[off_to];
if (hl > HL_ALL)
hl = syn_attr2attr(hl);
if (hl & HL_BOLD)
redraw_next = TRUE;
}
#endif
ScreenAttrs[off_to] = ScreenAttrs[off_from];
#ifdef FEAT_MBYTE
if (char_cells == 2)
ScreenAttrs[off_to + 1] = ScreenAttrs[off_from];
if (enc_dbcs != 0 && char_cells == 2)
screen_char_2(off_to, row, col + coloff);
else
#endif
screen_char(off_to, row, col + coloff);
}
else if ( p_wiv
#ifdef FEAT_GUI
&& !gui.in_use
#endif
&& col + coloff > 0)
{
if (ScreenAttrs[off_to] == ScreenAttrs[off_to - 1])
{
screen_attr = 0;
}
else if (screen_attr != 0)
screen_stop_highlight();
}
off_to += CHAR_CELLS;
off_from += CHAR_CELLS;
col += CHAR_CELLS;
}
#ifdef FEAT_MBYTE
if (clear_next)
{
ScreenLines[off_to] = ' ';
if (enc_utf8)
ScreenLinesUC[off_to] = 0;
screen_char(off_to, row, col + coloff);
}
#endif
if (clear_width > 0
#ifdef FEAT_RIGHTLEFT
&& !rlflag
#endif
)
{
#ifdef FEAT_GUI
int startCol = col;
#endif
while (col < clear_width && ScreenLines[off_to] == ' '
&& ScreenAttrs[off_to] == 0
#ifdef FEAT_MBYTE
&& (!enc_utf8 || ScreenLinesUC[off_to] == 0)
#endif
)
{
++off_to;
++col;
}
if (col < clear_width)
{
#ifdef FEAT_GUI
if (gui.in_use && (col > startCol || !redraw_this))
{
hl = ScreenAttrs[off_to];
if (hl > HL_ALL || (hl & HL_BOLD))
{
int prev_cells = 1;
# ifdef FEAT_MBYTE
if (enc_utf8)
prev_cells = ScreenLines[off_to - 1] == 0 ? 2 : 1;
else if (enc_dbcs != 0)
{
unsigned off = LineOffset[row];
unsigned max_off = LineOffset[row] + screen_Columns;
while (off < off_to)
{
prev_cells = (*mb_off2cells)(off, max_off);
off += prev_cells;
}
}
if (enc_dbcs != 0 && prev_cells > 1)
screen_char_2(off_to - prev_cells, row,
col + coloff - prev_cells);
else
# endif
screen_char(off_to - prev_cells, row,
col + coloff - prev_cells);
}
}
#endif
screen_fill(row, row + 1, col + coloff, clear_width + coloff,
' ', ' ', 0);
off_to += clear_width - col;
col = clear_width;
}
}
if (clear_width > 0)
{
if (col + coloff < Columns)
{
int c;
c = fillchar_vsep(&hl);
if (ScreenLines[off_to] != (schar_T)c
#ifdef FEAT_MBYTE
|| (enc_utf8 && (int)ScreenLinesUC[off_to]
!= (c >= 0x80 ? c : 0))
#endif
|| ScreenAttrs[off_to] != hl)
{
ScreenLines[off_to] = c;
ScreenAttrs[off_to] = hl;
#ifdef FEAT_MBYTE
if (enc_utf8)
{
if (c >= 0x80)
{
ScreenLinesUC[off_to] = c;
ScreenLinesC[0][off_to] = 0;
}
else
ScreenLinesUC[off_to] = 0;
}
#endif
screen_char(off_to, row, col + coloff);
}
}
else
LineWraps[row] = FALSE;
}
}
#if defined(FEAT_RIGHTLEFT) || defined(PROTO)
void
rl_mirror(char_u *str)
{
char_u *p1, *p2;
int t;
for (p1 = str, p2 = str + STRLEN(str) - 1; p1 < p2; ++p1, --p2)
{
t = *p1;
*p1 = *p2;
*p2 = t;
}
}
#endif
void
status_redraw_all(void)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
if (wp->w_status_height)
{
wp->w_redr_status = TRUE;
redraw_later(VALID);
}
}
void
status_redraw_curbuf(void)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
if (wp->w_status_height != 0 && wp->w_buffer == curbuf)
{
wp->w_redr_status = TRUE;
redraw_later(VALID);
}
}
void
redraw_statuslines(void)
{
win_T *wp;
FOR_ALL_WINDOWS(wp)
if (wp->w_redr_status)
win_redr_status(wp);
if (redraw_tabline)
draw_tabline();
}
#if defined(FEAT_WILDMENU) || defined(PROTO)
void
win_redraw_last_status(frame_T *frp)
{
if (frp->fr_layout == FR_LEAF)
frp->fr_win->w_redr_status = TRUE;
else if (frp->fr_layout == FR_ROW)
{
for (frp = frp->fr_child; frp != NULL; frp = frp->fr_next)
win_redraw_last_status(frp);
}
else
{
frp = frp->fr_child;
while (frp->fr_next != NULL)
frp = frp->fr_next;
win_redraw_last_status(frp);
}
}
#endif
static void
draw_vsep_win(win_T *wp, int row)
{
int hl;
int c;
if (wp->w_vsep_width)
{
c = fillchar_vsep(&hl);
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
W_ENDCOL(wp), W_ENDCOL(wp) + 1,
c, ' ', hl);
}
}
#ifdef FEAT_WILDMENU
static int status_match_len(expand_T *xp, char_u *s);
static int skip_status_match_char(expand_T *xp, char_u *s);
static int
status_match_len(expand_T *xp, char_u *s)
{
int len = 0;
#ifdef FEAT_MENU
int emenu = (xp->xp_context == EXPAND_MENUS
|| xp->xp_context == EXPAND_MENUNAMES);
if (emenu && menu_is_separator(s))
return 1;
#endif
while (*s != NUL)
{
s += skip_status_match_char(xp, s);
len += ptr2cells(s);
MB_PTR_ADV(s);
}
return len;
}
static int
skip_status_match_char(expand_T *xp, char_u *s)
{
if ((rem_backslash(s) && xp->xp_context != EXPAND_HELP)
#ifdef FEAT_MENU
|| ((xp->xp_context == EXPAND_MENUS
|| xp->xp_context == EXPAND_MENUNAMES)
&& (s[0] == '\t' || (s[0] == '\\' && s[1] != NUL)))
#endif
)
{
#ifndef BACKSLASH_IN_FILENAME
if (xp->xp_shell && csh_like_shell() && s[1] == '\\' && s[2] == '!')
return 2;
#endif
return 1;
}
return 0;
}
void
win_redr_status_matches(
expand_T *xp,
int num_matches,
char_u **matches,
int match,
int showtail)
{
#define L_MATCH(m) (showtail ? sm_gettail(matches[m]) : matches[m])
int row;
char_u *buf;
int len;
int clen;
int fillchar;
int attr;
int i;
int highlight = TRUE;
char_u *selstart = NULL;
int selstart_col = 0;
char_u *selend = NULL;
static int first_match = 0;
int add_left = FALSE;
char_u *s;
#ifdef FEAT_MENU
int emenu;
#endif
#if defined(FEAT_MBYTE) || defined(FEAT_MENU)
int l;
#endif
if (matches == NULL)
return;
#ifdef FEAT_MBYTE
if (has_mbyte)
buf = alloc((unsigned)Columns * MB_MAXBYTES + 1);
else
#endif
buf = alloc((unsigned)Columns + 1);
if (buf == NULL)
return;
if (match == -1)
{
match = 0;
highlight = FALSE;
}
clen = status_match_len(xp, L_MATCH(match)) + 3;
if (match == 0)
first_match = 0;
else if (match < first_match)
{
first_match = match;
add_left = TRUE;
}
else
{
for (i = first_match; i < match; ++i)
clen += status_match_len(xp, L_MATCH(i)) + 2;
if (first_match > 0)
clen += 2;
if ((long)clen > Columns)
{
first_match = match;
clen = 2;
for (i = match; i < num_matches; ++i)
{
clen += status_match_len(xp, L_MATCH(i)) + 2;
if ((long)clen >= Columns)
break;
}
if (i == num_matches)
add_left = TRUE;
}
}
if (add_left)
while (first_match > 0)
{
clen += status_match_len(xp, L_MATCH(first_match - 1)) + 2;
if ((long)clen >= Columns)
break;
--first_match;
}
fillchar = fillchar_status(&attr, curwin);
if (first_match == 0)
{
*buf = NUL;
len = 0;
}
else
{
STRCPY(buf, "< ");
len = 2;
}
clen = len;
i = first_match;
while ((long)(clen + status_match_len(xp, L_MATCH(i)) + 2) < Columns)
{
if (i == match)
{
selstart = buf + len;
selstart_col = clen;
}
s = L_MATCH(i);
#ifdef FEAT_MENU
emenu = (xp->xp_context == EXPAND_MENUS
|| xp->xp_context == EXPAND_MENUNAMES);
if (emenu && menu_is_separator(s))
{
STRCPY(buf + len, transchar('|'));
l = (int)STRLEN(buf + len);
len += l;
clen += l;
}
else
#endif
for ( ; *s != NUL; ++s)
{
s += skip_status_match_char(xp, s);
clen += ptr2cells(s);
#ifdef FEAT_MBYTE
if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1)
{
STRNCPY(buf + len, s, l);
s += l - 1;
len += l;
}
else
#endif
{
STRCPY(buf + len, transchar_byte(*s));
len += (int)STRLEN(buf + len);
}
}
if (i == match)
selend = buf + len;
*(buf + len++) = ' ';
*(buf + len++) = ' ';
clen += 2;
if (++i == num_matches)
break;
}
if (i != num_matches)
{
*(buf + len++) = '>';
++clen;
}
buf[len] = NUL;
row = cmdline_row - 1;
if (row >= 0)
{
if (wild_menu_showing == 0)
{
if (msg_scrolled > 0)
{
if (cmdline_row == Rows - 1)
{
screen_del_lines(0, 0, 1, (int)Rows, TRUE, 0, NULL);
++msg_scrolled;
}
else
{
++cmdline_row;
++row;
}
wild_menu_showing = WM_SCROLLED;
}
else
{
if (lastwin->w_status_height == 0)
{
save_p_ls = p_ls;
save_p_wmh = p_wmh;
p_ls = 2;
p_wmh = 0;
last_status(FALSE);
}
wild_menu_showing = WM_SHOWN;
}
}
screen_puts(buf, row, 0, attr);
if (selstart != NULL && highlight)
{
*selend = NUL;
screen_puts(selstart, row, selstart_col, HL_ATTR(HLF_WM));
}
screen_fill(row, row + 1, clen, (int)Columns, fillchar, fillchar, attr);
}
win_redraw_last_status(topframe);
vim_free(buf);
}
#endif
void
win_redr_status(win_T *wp)
{
int row;
char_u *p;
int len;
int fillchar;
int attr;
int this_ru_col;
static int busy = FALSE;
if (busy)
return;
busy = TRUE;
wp->w_redr_status = FALSE;
if (wp->w_status_height == 0)
{
redraw_cmdline = TRUE;
}
else if (!redrawing()
#ifdef FEAT_INS_EXPAND
|| pum_visible()
#endif
)
{
wp->w_redr_status = TRUE;
}
#ifdef FEAT_STL_OPT
else if (*p_stl != NUL || *wp->w_p_stl != NUL)
{
redraw_custom_statusline(wp);
}
#endif
else
{
fillchar = fillchar_status(&attr, wp);
get_trans_bufname(wp->w_buffer);
p = NameBuff;
len = (int)STRLEN(p);
if (bt_help(wp->w_buffer)
#ifdef FEAT_QUICKFIX
|| wp->w_p_pvw
#endif
|| bufIsChanged(wp->w_buffer)
|| wp->w_buffer->b_p_ro)
*(p + len++) = ' ';
if (bt_help(wp->w_buffer))
{
STRCPY(p + len, _("[Help]"));
len += (int)STRLEN(p + len);
}
#ifdef FEAT_QUICKFIX
if (wp->w_p_pvw)
{
STRCPY(p + len, _("[Preview]"));
len += (int)STRLEN(p + len);
}
#endif
if (bufIsChanged(wp->w_buffer)
#ifdef FEAT_TERMINAL
&& !bt_terminal(wp->w_buffer)
#endif
)
{
STRCPY(p + len, "[+]");
len += 3;
}
if (wp->w_buffer->b_p_ro)
{
STRCPY(p + len, _("[RO]"));
len += (int)STRLEN(p + len);
}
this_ru_col = ru_col - (Columns - wp->w_width);
if (this_ru_col < (wp->w_width + 1) / 2)
this_ru_col = (wp->w_width + 1) / 2;
if (this_ru_col <= 1)
{
p = (char_u *)"<";
len = 1;
}
else
#ifdef FEAT_MBYTE
if (has_mbyte)
{
int clen = 0, i;
clen = mb_string2cells(p, -1);
for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
i += (*mb_ptr2len)(p + i))
clen -= (*mb_ptr2cells)(p + i);
len = clen;
if (i > 0)
{
p = p + i - 1;
*p = '<';
++len;
}
}
else
#endif
if (len > this_ru_col - 1)
{
p += len - (this_ru_col - 1);
*p = '<';
len = this_ru_col - 1;
}
row = W_WINROW(wp) + wp->w_height;
screen_puts(p, row, wp->w_wincol, attr);
screen_fill(row, row + 1, len + wp->w_wincol,
this_ru_col + wp->w_wincol, fillchar, fillchar, attr);
if (get_keymap_str(wp, (char_u *)"<%s>", NameBuff, MAXPATHL)
&& (int)(this_ru_col - len) > (int)(STRLEN(NameBuff) + 1))
screen_puts(NameBuff, row, (int)(this_ru_col - STRLEN(NameBuff)
- 1 + wp->w_wincol), attr);
#ifdef FEAT_CMDL_INFO
win_redr_ruler(wp, TRUE);
#endif
}
if (wp->w_vsep_width != 0 && wp->w_status_height != 0 && redrawing())
{
if (stl_connected(wp))
fillchar = fillchar_status(&attr, wp);
else
fillchar = fillchar_vsep(&attr);
screen_putchar(fillchar, W_WINROW(wp) + wp->w_height, W_ENDCOL(wp),
attr);
}
busy = FALSE;
}
#ifdef FEAT_STL_OPT
static void
redraw_custom_statusline(win_T *wp)
{
static int entered = FALSE;
int saved_did_emsg = did_emsg;
if (entered)
return;
entered = TRUE;
did_emsg = FALSE;
win_redr_custom(wp, FALSE);
if (did_emsg)
{
set_string_option_direct((char_u *)"statusline", -1,
(char_u *)"", OPT_FREE | (*wp->w_p_stl != NUL
? OPT_LOCAL : OPT_GLOBAL), SID_ERROR);
}
did_emsg |= saved_did_emsg;
entered = FALSE;
}
#endif
int
stl_connected(win_T *wp)
{
frame_T *fr;
fr = wp->w_frame;
while (fr->fr_parent != NULL)
{
if (fr->fr_parent->fr_layout == FR_COL)
{
if (fr->fr_next != NULL)
break;
}
else
{
if (fr->fr_next != NULL)
return TRUE;
}
fr = fr->fr_parent;
}
return FALSE;
}
int
get_keymap_str(
win_T *wp,
char_u *fmt,
char_u *buf,
int len)
{
char_u *p;
if (wp->w_buffer->b_p_iminsert != B_IMODE_LMAP)
return FALSE;
{
#ifdef FEAT_EVAL
buf_T *old_curbuf = curbuf;
win_T *old_curwin = curwin;
char_u *s;
curbuf = wp->w_buffer;
curwin = wp;
STRCPY(buf, "b:keymap_name");
++emsg_skip;
s = p = eval_to_string(buf, NULL, FALSE);
--emsg_skip;
curbuf = old_curbuf;
curwin = old_curwin;
if (p == NULL || *p == NUL)
#endif
{
#ifdef FEAT_KEYMAP
if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED)
p = wp->w_buffer->b_p_keymap;
else
#endif
p = (char_u *)"lang";
}
if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1)
buf[0] = NUL;
#ifdef FEAT_EVAL
vim_free(s);
#endif
}
return buf[0] != NUL;
}
#if defined(FEAT_STL_OPT) || defined(PROTO)
static void
win_redr_custom(
win_T *wp,
int draw_ruler)
{
static int entered = FALSE;
int attr;
int curattr;
int row;
int col = 0;
int maxwidth;
int width;
int n;
int len;
int fillchar;
char_u buf[MAXPATHL];
char_u *stl;
char_u *p;
struct stl_hlrec hltab[STL_MAX_ITEM];
struct stl_hlrec tabtab[STL_MAX_ITEM];
int use_sandbox = FALSE;
win_T *ewp;
int p_crb_save;
if (entered)
return;
entered = TRUE;
if (wp == NULL)
{
stl = p_tal;
row = 0;
fillchar = ' ';
attr = HL_ATTR(HLF_TPF);
maxwidth = Columns;
# ifdef FEAT_EVAL
use_sandbox = was_set_insecurely((char_u *)"tabline", 0);
# endif
}
else
{
row = W_WINROW(wp) + wp->w_height;
fillchar = fillchar_status(&attr, wp);
maxwidth = wp->w_width;
if (draw_ruler)
{
stl = p_ruf;
if (*stl == '%')
{
if (*++stl == '-')
stl++;
if (atoi((char *)stl))
while (VIM_ISDIGIT(*stl))
stl++;
if (*stl++ != '(')
stl = p_ruf;
}
col = ru_col - (Columns - wp->w_width);
if (col < (wp->w_width + 1) / 2)
col = (wp->w_width + 1) / 2;
maxwidth = wp->w_width - col;
if (!wp->w_status_height)
{
row = Rows - 1;
--maxwidth;
fillchar = ' ';
attr = 0;
}
# ifdef FEAT_EVAL
use_sandbox = was_set_insecurely((char_u *)"rulerformat", 0);
# endif
}
else
{
if (*wp->w_p_stl != NUL)
stl = wp->w_p_stl;
else
stl = p_stl;
# ifdef FEAT_EVAL
use_sandbox = was_set_insecurely((char_u *)"statusline",
*wp->w_p_stl == NUL ? 0 : OPT_LOCAL);
# endif
}
col += wp->w_wincol;
}
if (maxwidth <= 0)
goto theend;
ewp = wp == NULL ? curwin : wp;
p_crb_save = ewp->w_p_crb;
ewp->w_p_crb = FALSE;
stl = vim_strsave(stl);
width = build_stl_str_hl(ewp, buf, sizeof(buf),
stl, use_sandbox,
fillchar, maxwidth, hltab, tabtab);
vim_free(stl);
ewp->w_p_crb = p_crb_save;
p = transstr(buf);
if (p != NULL)
{
vim_strncpy(buf, p, sizeof(buf) - 1);
vim_free(p);
}
len = (int)STRLEN(buf);
while (width < maxwidth && len < (int)sizeof(buf) - 1)
{
#ifdef FEAT_MBYTE
len += (*mb_char2bytes)(fillchar, buf + len);
#else
buf[len++] = fillchar;
#endif
++width;
}
buf[len] = NUL;
curattr = attr;
p = buf;
for (n = 0; hltab[n].start != NULL; n++)
{
len = (int)(hltab[n].start - p);
screen_puts_len(p, len, row, col, curattr);
col += vim_strnsize(p, len);
p = hltab[n].start;
if (hltab[n].userhl == 0)
curattr = attr;
else if (hltab[n].userhl < 0)
curattr = syn_id2attr(-hltab[n].userhl);
#ifdef FEAT_TERMINAL
else if (wp != NULL && wp != curwin && bt_terminal(wp->w_buffer)
&& wp->w_status_height != 0)
curattr = highlight_stltermnc[hltab[n].userhl - 1];
else if (wp != NULL && bt_terminal(wp->w_buffer)
&& wp->w_status_height != 0)
curattr = highlight_stlterm[hltab[n].userhl - 1];
#endif
else if (wp != NULL && wp != curwin && wp->w_status_height != 0)
curattr = highlight_stlnc[hltab[n].userhl - 1];
else
curattr = highlight_user[hltab[n].userhl - 1];
}
screen_puts(p, row, col, curattr);
if (wp == NULL)
{
col = 0;
len = 0;
p = buf;
fillchar = 0;
for (n = 0; tabtab[n].start != NULL; n++)
{
len += vim_strnsize(p, (int)(tabtab[n].start - p));
while (col < len)
TabPageIdxs[col++] = fillchar;
p = tabtab[n].start;
fillchar = tabtab[n].userhl;
}
while (col < Columns)
TabPageIdxs[col++] = fillchar;
}
theend:
entered = FALSE;
}
#endif
void
screen_putchar(int c, int row, int col, int attr)
{
char_u buf[MB_MAXBYTES + 1];
#ifdef FEAT_MBYTE
if (has_mbyte)
buf[(*mb_char2bytes)(c, buf)] = NUL;
else
#endif
{
buf[0] = c;
buf[1] = NUL;
}
screen_puts(buf, row, col, attr);
}
void
screen_getbytes(int row, int col, char_u *bytes, int *attrp)
{
unsigned off;
if (ScreenLines != NULL && row < screen_Rows && col < screen_Columns)
{
off = LineOffset[row] + col;
*attrp = ScreenAttrs[off];
bytes[0] = ScreenLines[off];
bytes[1] = NUL;
#ifdef FEAT_MBYTE
if (enc_utf8 && ScreenLinesUC[off] != 0)
bytes[utfc_char2bytes(off, bytes)] = NUL;
else if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
{
bytes[0] = ScreenLines[off];
bytes[1] = ScreenLines2[off];
bytes[2] = NUL;
}
else if (enc_dbcs && MB_BYTE2LEN(bytes[0]) > 1)
{
bytes[1] = ScreenLines[off + 1];
bytes[2] = NUL;
}
#endif
}
}
#ifdef FEAT_MBYTE
static int screen_comp_differs(int, int*);
static int
screen_comp_differs(int off, int *u8cc)
{
int i;
for (i = 0; i < Screen_mco; ++i)
{
if (ScreenLinesC[i][off] != (u8char_T)u8cc[i])
return TRUE;
if (u8cc[i] == 0)
break;
}
return FALSE;
}
#endif
void
screen_puts(
char_u *text,
int row,
int col,
int attr)
{
screen_puts_len(text, -1, row, col, attr);
}
void
screen_puts_len(
char_u *text,
int textlen,
int row,
int col,
int attr)
{
unsigned off;
char_u *ptr = text;
int len = textlen;
int c;
#ifdef FEAT_MBYTE
unsigned max_off;
int mbyte_blen = 1;
int mbyte_cells = 1;
int u8c = 0;
int u8cc[MAX_MCO];
int clear_next_cell = FALSE;
# ifdef FEAT_ARABIC
int prev_c = 0;
int pc, nc, nc1;
int pcc[MAX_MCO];
# endif
#endif
#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
int force_redraw_this;
int force_redraw_next = FALSE;
#endif
int need_redraw;
if (ScreenLines == NULL || row >= screen_Rows)
return;
off = LineOffset[row] + col;
#ifdef FEAT_MBYTE
if (has_mbyte && col > 0 && col < screen_Columns
# ifdef FEAT_GUI
&& !gui.in_use
# endif
&& mb_fix_col(col, row) != col)
{
ScreenLines[off - 1] = ' ';
ScreenAttrs[off - 1] = 0;
if (enc_utf8)
{
ScreenLinesUC[off - 1] = 0;
ScreenLinesC[0][off - 1] = 0;
}
screen_char(off - 1, row, col - 1);
force_redraw_next = TRUE;
}
#endif
#ifdef FEAT_MBYTE
max_off = LineOffset[row] + screen_Columns;
#endif
while (col < screen_Columns
&& (len < 0 || (int)(ptr - text) < len)
&& *ptr != NUL)
{
c = *ptr;
#ifdef FEAT_MBYTE
if (has_mbyte)
{
if (enc_utf8 && len > 0)
mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr));
else
mbyte_blen = (*mb_ptr2len)(ptr);
if (enc_dbcs == DBCS_JPNU && c == 0x8e)
mbyte_cells = 1;
else if (enc_dbcs != 0)
mbyte_cells = mbyte_blen;
else
{
if (len >= 0)
u8c = utfc_ptr2char_len(ptr, u8cc,
(int)((text + len) - ptr));
else
u8c = utfc_ptr2char(ptr, u8cc);
mbyte_cells = utf_char2cells(u8c);
# ifdef UNICODE16
if (u8c >= 0x10000)
{
u8c = (mbyte_cells == 2) ? 0xff1f : (int)'?';
if (attr == 0)
attr = HL_ATTR(HLF_8);
}
# endif
# ifdef FEAT_ARABIC
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c))
{
if (len >= 0 && (int)(ptr - text) + mbyte_blen >= len)
{
nc = NUL;
nc1 = NUL;
}
else
{
nc = utfc_ptr2char_len(ptr + mbyte_blen, pcc,
(int)((text + len) - ptr - mbyte_blen));
nc1 = pcc[0];
}
pc = prev_c;
prev_c = u8c;
u8c = arabic_shape(u8c, &c, &u8cc[0], nc, nc1, pc);
}
else
prev_c = u8c;
# endif
if (col + mbyte_cells > screen_Columns)
{
c = '>';
mbyte_cells = 1;
}
}
}
#endif
#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
force_redraw_this = force_redraw_next;
force_redraw_next = FALSE;
#endif
need_redraw = ScreenLines[off] != c
#ifdef FEAT_MBYTE
|| (mbyte_cells == 2
&& ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0))
|| (enc_dbcs == DBCS_JPNU
&& c == 0x8e
&& ScreenLines2[off] != ptr[1])
|| (enc_utf8
&& (ScreenLinesUC[off] !=
(u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c)
|| (ScreenLinesUC[off] != 0
&& screen_comp_differs(off, u8cc))))
#endif
|| ScreenAttrs[off] != attr
|| exmode_active;
if (need_redraw
#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
|| force_redraw_this
#endif
)
{
#if defined(FEAT_GUI) || defined(UNIX)
if (need_redraw && ScreenLines[off] != ' ' && (
# ifdef FEAT_GUI
gui.in_use
# endif
# if defined(FEAT_GUI) && defined(UNIX)
||
# endif
# ifdef UNIX
term_is_xterm
# endif
))
{
int n = ScreenAttrs[off];
if (n > HL_ALL)
n = syn_attr2attr(n);
if (n & HL_BOLD)
force_redraw_next = TRUE;
}
#endif
#ifdef FEAT_MBYTE
if (clear_next_cell)
clear_next_cell = FALSE;
else if (has_mbyte
&& (len < 0 ? ptr[mbyte_blen] == NUL
: ptr + mbyte_blen >= text + len)
&& ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
|| (mbyte_cells == 2
&& (*mb_off2cells)(off, max_off) == 1
&& (*mb_off2cells)(off + 1, max_off) > 1)))
clear_next_cell = TRUE;
if (enc_dbcs
&& ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
|| (mbyte_cells == 2
&& (*mb_off2cells)(off, max_off) == 1
&& (*mb_off2cells)(off + 1, max_off) > 1)))
ScreenLines[off + mbyte_blen] = 0;
#endif
ScreenLines[off] = c;
ScreenAttrs[off] = attr;
#ifdef FEAT_MBYTE
if (enc_utf8)
{
if (c < 0x80 && u8cc[0] == 0)
ScreenLinesUC[off] = 0;
else
{
int i;
ScreenLinesUC[off] = u8c;
for (i = 0; i < Screen_mco; ++i)
{
ScreenLinesC[i][off] = u8cc[i];
if (u8cc[i] == 0)
break;
}
}
if (mbyte_cells == 2)
{
ScreenLines[off + 1] = 0;
ScreenAttrs[off + 1] = attr;
}
screen_char(off, row, col);
}
else if (mbyte_cells == 2)
{
ScreenLines[off + 1] = ptr[1];
ScreenAttrs[off + 1] = attr;
screen_char_2(off, row, col);
}
else if (enc_dbcs == DBCS_JPNU && c == 0x8e)
{
ScreenLines2[off] = ptr[1];
screen_char(off, row, col);
}
else
#endif
screen_char(off, row, col);
}
#ifdef FEAT_MBYTE
if (has_mbyte)
{
off += mbyte_cells;
col += mbyte_cells;
ptr += mbyte_blen;
if (clear_next_cell)
{
ptr = (char_u *)" ";
len = -1;
}
}
else
#endif
{
++off;
++col;
++ptr;
}
}
#if defined(FEAT_MBYTE) || defined(FEAT_GUI) || defined(UNIX)
if (force_redraw_next && col < screen_Columns)
{
# ifdef FEAT_MBYTE
if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1)
screen_char_2(off, row, col);
else
# endif
screen_char(off, row, col);
}
#endif
}
#ifdef FEAT_SEARCH_EXTRA
static void
start_search_hl(void)
{
if (p_hls && !no_hlsearch)
{
last_pat_prog(&search_hl.rm);
search_hl.attr = HL_ATTR(HLF_L);
# ifdef FEAT_RELTIME
profile_setlimit(p_rdt, &search_hl.tm);
# endif
}
}
static void
end_search_hl(void)
{
if (search_hl.rm.regprog != NULL)
{
vim_regfree(search_hl.rm.regprog);
search_hl.rm.regprog = NULL;
}
}
static void
init_search_hl(win_T *wp)
{
matchitem_T *cur;
cur = wp->w_match_head;
while (cur != NULL)
{
cur->hl.rm = cur->match;
if (cur->hlg_id == 0)
cur->hl.attr = 0;
else
cur->hl.attr = syn_id2attr(cur->hlg_id);
cur->hl.buf = wp->w_buffer;
cur->hl.lnum = 0;
cur->hl.first_lnum = 0;
# ifdef FEAT_RELTIME
profile_setlimit(p_rdt, &(cur->hl.tm));
# endif
cur = cur->next;
}
search_hl.buf = wp->w_buffer;
search_hl.lnum = 0;
search_hl.first_lnum = 0;
}
static void
prepare_search_hl(win_T *wp, linenr_T lnum)
{
matchitem_T *cur;
match_T *shl;
int shl_flag;
int pos_inprogress;
int n;
cur = wp->w_match_head;
shl_flag = FALSE;
while (cur != NULL || shl_flag == FALSE)
{
if (shl_flag == FALSE)
{
shl = &search_hl;
shl_flag = TRUE;
}
else
shl = &cur->hl;
if (shl->rm.regprog != NULL
&& shl->lnum == 0
&& re_multiline(shl->rm.regprog))
{
if (shl->first_lnum == 0)
{
# ifdef FEAT_FOLDING
for (shl->first_lnum = lnum;
shl->first_lnum > wp->w_topline; --shl->first_lnum)
if (hasFoldingWin(wp, shl->first_lnum - 1,
NULL, NULL, TRUE, NULL))
break;
# else
shl->first_lnum = wp->w_topline;
# endif
}
if (cur != NULL)
cur->pos.cur = 0;
pos_inprogress = TRUE;
n = 0;
while (shl->first_lnum < lnum && (shl->rm.regprog != NULL
|| (cur != NULL && pos_inprogress)))
{
next_search_hl(wp, shl, shl->first_lnum, (colnr_T)n,
shl == &search_hl ? NULL : cur);
pos_inprogress = cur == NULL || cur->pos.cur == 0
? FALSE : TRUE;
if (shl->lnum != 0)
{
shl->first_lnum = shl->lnum
+ shl->rm.endpos[0].lnum
- shl->rm.startpos[0].lnum;
n = shl->rm.endpos[0].col;
}
else
{
++shl->first_lnum;
n = 0;
}
}
}
if (shl != &search_hl && cur != NULL)
cur = cur->next;
}
}
static void
next_search_hl(
win_T *win,
match_T *shl,
linenr_T lnum,
colnr_T mincol,
matchitem_T *cur)
{
linenr_T l;
colnr_T matchcol;
long nmatched;
if (shl->lnum != 0)
{
l = shl->lnum + shl->rm.endpos[0].lnum - shl->rm.startpos[0].lnum;
if (lnum > l)
shl->lnum = 0;
else if (lnum < l || shl->rm.endpos[0].col > mincol)
return;
}
called_emsg = FALSE;
for (;;)
{
#ifdef FEAT_RELTIME
if (profile_passed_limit(&(shl->tm)))
{
shl->lnum = 0;
break;
}
#endif
if (shl->lnum == 0)
matchcol = 0;
else if (vim_strchr(p_cpo, CPO_SEARCH) == NULL
|| (shl->rm.endpos[0].lnum == 0
&& shl->rm.endpos[0].col <= shl->rm.startpos[0].col))
{
char_u *ml;
matchcol = shl->rm.startpos[0].col;
ml = ml_get_buf(shl->buf, lnum, FALSE) + matchcol;
if (*ml == NUL)
{
++matchcol;
shl->lnum = 0;
break;
}
#ifdef FEAT_MBYTE
if (has_mbyte)
matchcol += mb_ptr2len(ml);
else
#endif
++matchcol;
}
else
matchcol = shl->rm.endpos[0].col;
shl->lnum = lnum;
if (shl->rm.regprog != NULL)
{
int regprog_is_copy = (shl != &search_hl && cur != NULL
&& shl == &cur->hl
&& cur->match.regprog == cur->hl.rm.regprog);
int timed_out = FALSE;
nmatched = vim_regexec_multi(&shl->rm, win, shl->buf, lnum,
matchcol,
#ifdef FEAT_RELTIME
&(shl->tm), &timed_out
#else
NULL, NULL
#endif
);
if (regprog_is_copy)
cur->match.regprog = cur->hl.rm.regprog;
if (called_emsg || got_int || timed_out)
{
if (shl == &search_hl)
{
vim_regfree(shl->rm.regprog);
SET_NO_HLSEARCH(TRUE);
}
shl->rm.regprog = NULL;
shl->lnum = 0;
got_int = FALSE;
break;
}
}
else if (cur != NULL)
nmatched = next_search_hl_pos(shl, lnum, &(cur->pos), matchcol);
else
nmatched = 0;
if (nmatched == 0)
{
shl->lnum = 0;
break;
}
if (shl->rm.startpos[0].lnum > 0
|| shl->rm.startpos[0].col >= mincol
|| nmatched > 1
|| shl->rm.endpos[0].col > mincol)
{
shl->lnum += shl->rm.startpos[0].lnum;
break;
}
}
}
static int
next_search_hl_pos(
match_T *shl,
linenr_T lnum,
posmatch_T *posmatch,
colnr_T mincol)
{
int i;
int found = -1;
for (i = posmatch->cur; i < MAXPOSMATCH; i++)
{
llpos_T *pos = &posmatch->pos[i];
if (pos->lnum == 0)
break;
if (pos->len == 0 && pos->col < mincol)
continue;
if (pos->lnum == lnum)
{
if (found >= 0)
{
if (pos->col < posmatch->pos[found].col)
{
llpos_T tmp = *pos;
*pos = posmatch->pos[found];
posmatch->pos[found] = tmp;
}
}
else
found = i;
}
}
posmatch->cur = 0;
if (found >= 0)
{
colnr_T start = posmatch->pos[found].col == 0
? 0 : posmatch->pos[found].col - 1;
colnr_T end = posmatch->pos[found].col == 0
? MAXCOL : start + posmatch->pos[found].len;
shl->lnum = lnum;
shl->rm.startpos[0].lnum = 0;
shl->rm.startpos[0].col = start;
shl->rm.endpos[0].lnum = 0;
shl->rm.endpos[0].col = end;
shl->is_addpos = TRUE;
posmatch->cur = found + 1;
return 1;
}
return 0;
}
#endif
static void
screen_start_highlight(int attr)
{
attrentry_T *aep = NULL;
screen_attr = attr;
if (full_screen
#ifdef WIN3264
&& termcap_active
#endif
)
{
#ifdef FEAT_GUI
if (gui.in_use)
{
char buf[20];
sprintf(buf, IF_EB("\033|%dh", ESC_STR "|%dh"), attr);
OUT_STR(buf);
}
else
#endif
{
if (attr > HL_ALL)
{
if (IS_CTERM)
aep = syn_cterm_attr2entry(attr);
else
aep = syn_term_attr2entry(attr);
if (aep == NULL)
attr = 0;
else
attr = aep->ae_attr;
}
if ((attr & HL_BOLD) && T_MD != NULL)
out_str(T_MD);
else if (aep != NULL && cterm_normal_fg_bold &&
#ifdef FEAT_TERMGUICOLORS
(p_tgc ?
(aep->ae_u.cterm.fg_rgb != INVALCOLOR):
#endif
(t_colors > 1 && aep->ae_u.cterm.fg_color)
#ifdef FEAT_TERMGUICOLORS
)
#endif
)
out_str(T_ME);
if ((attr & HL_STANDOUT) && T_SO != NULL)
out_str(T_SO);
if ((attr & (HL_UNDERLINE | HL_UNDERCURL)) && T_US != NULL)
out_str(T_US);
if ((attr & HL_ITALIC) && T_CZH != NULL)
out_str(T_CZH);
if ((attr & HL_INVERSE) && T_MR != NULL)
out_str(T_MR);
if ((attr & HL_STRIKETHROUGH) && T_STS != NULL)
out_str(T_STS);
if (aep != NULL)
{
#ifdef FEAT_TERMGUICOLORS
if (p_tgc)
{
if (aep->ae_u.cterm.fg_rgb != INVALCOLOR)
term_fg_rgb_color(aep->ae_u.cterm.fg_rgb);
if (aep->ae_u.cterm.bg_rgb != INVALCOLOR)
term_bg_rgb_color(aep->ae_u.cterm.bg_rgb);
}
else
#endif
{
if (t_colors > 1)
{
if (aep->ae_u.cterm.fg_color)
term_fg_color(aep->ae_u.cterm.fg_color - 1);
if (aep->ae_u.cterm.bg_color)
term_bg_color(aep->ae_u.cterm.bg_color - 1);
}
else
{
if (aep->ae_u.term.start != NULL)
out_str(aep->ae_u.term.start);
}
}
}
}
}
}
void
screen_stop_highlight(void)
{
int do_ME = FALSE;
if (screen_attr != 0
#ifdef WIN3264
&& termcap_active
#endif
)
{
#ifdef FEAT_GUI
if (gui.in_use)
{
char buf[20];
sprintf(buf, IF_EB("\033|%dH", ESC_STR "|%dH"), screen_attr);
OUT_STR(buf);
}
else
#endif
{
if (screen_attr > HL_ALL)
{
attrentry_T *aep;
if (IS_CTERM)
{
aep = syn_cterm_attr2entry(screen_attr);
if (aep != NULL &&
#ifdef FEAT_TERMGUICOLORS
(p_tgc ?
(aep->ae_u.cterm.fg_rgb != INVALCOLOR
|| aep->ae_u.cterm.bg_rgb != INVALCOLOR):
#endif
(aep->ae_u.cterm.fg_color || aep->ae_u.cterm.bg_color)
#ifdef FEAT_TERMGUICOLORS
)
#endif
)
do_ME = TRUE;
}
else
{
aep = syn_term_attr2entry(screen_attr);
if (aep != NULL && aep->ae_u.term.stop != NULL)
{
if (STRCMP(aep->ae_u.term.stop, T_ME) == 0)
do_ME = TRUE;
else
out_str(aep->ae_u.term.stop);
}
}
if (aep == NULL)
screen_attr = 0;
else
screen_attr = aep->ae_attr;
}
if (screen_attr & HL_STANDOUT)
{
if (STRCMP(T_SE, T_ME) == 0)
do_ME = TRUE;
else
out_str(T_SE);
}
if (screen_attr & (HL_UNDERLINE | HL_UNDERCURL))
{
if (STRCMP(T_UE, T_ME) == 0)
do_ME = TRUE;
else
out_str(T_UE);
}
if (screen_attr & HL_ITALIC)
{
if (STRCMP(T_CZR, T_ME) == 0)
do_ME = TRUE;
else
out_str(T_CZR);
}
if (screen_attr & HL_STRIKETHROUGH)
{
if (STRCMP(T_STE, T_ME) == 0)
do_ME = TRUE;
else
out_str(T_STE);
}
if (do_ME || (screen_attr & (HL_BOLD | HL_INVERSE)))
out_str(T_ME);
#ifdef FEAT_TERMGUICOLORS
if (p_tgc)
{
if (cterm_normal_fg_gui_color != INVALCOLOR)
term_fg_rgb_color(cterm_normal_fg_gui_color);
if (cterm_normal_bg_gui_color != INVALCOLOR)
term_bg_rgb_color(cterm_normal_bg_gui_color);
}
else
#endif
{
if (t_colors > 1)
{
if (cterm_normal_fg_color != 0)
term_fg_color(cterm_normal_fg_color - 1);
if (cterm_normal_bg_color != 0)
term_bg_color(cterm_normal_bg_color - 1);
if (cterm_normal_fg_bold)
out_str(T_MD);
}
}
}
}
screen_attr = 0;
}
void
reset_cterm_colors(void)
{
if (IS_CTERM)
{
#ifdef FEAT_TERMGUICOLORS
if (p_tgc ? (cterm_normal_fg_gui_color != INVALCOLOR
|| cterm_normal_bg_gui_color != INVALCOLOR)
: (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0))
#else
if (cterm_normal_fg_color > 0 || cterm_normal_bg_color > 0)
#endif
{
out_str(T_OP);
screen_attr = -1;
}
if (cterm_normal_fg_bold)
{
out_str(T_ME);
screen_attr = -1;
}
}
}
static void
screen_char(unsigned off, int row, int col)
{
int attr;
if (row >= screen_Rows || col >= screen_Columns)
return;
if (*T_XN == NUL
&& row == screen_Rows - 1 && col == screen_Columns - 1
#ifdef FEAT_RIGHTLEFT
&& !cmdmsg_rl
#endif
)
{
ScreenAttrs[off] = (sattr_T)-1;
return;
}
if (screen_char_attr != 0)
attr = screen_char_attr;
else
attr = ScreenAttrs[off];
if (screen_attr != attr)
screen_stop_highlight();
windgoto(row, col);
if (screen_attr != attr)
screen_start_highlight(attr);
#ifdef FEAT_MBYTE
if (enc_utf8 && ScreenLinesUC[off] != 0)
{
char_u buf[MB_MAXBYTES + 1];
buf[utfc_char2bytes(off, buf)] = NUL;
out_str(buf);
if (utf_ambiguous_width(ScreenLinesUC[off]))
screen_cur_col = 9999;
else if (utf_char2cells(ScreenLinesUC[off]) > 1)
++screen_cur_col;
}
else
#endif
{
#ifdef FEAT_MBYTE
out_flush_check();
#endif
out_char(ScreenLines[off]);
#ifdef FEAT_MBYTE
if (enc_dbcs == DBCS_JPNU && ScreenLines[off] == 0x8e)
out_char(ScreenLines2[off]);
#endif
}
screen_cur_col++;
}
#ifdef FEAT_MBYTE
static void
screen_char_2(unsigned off, int row, int col)
{
if (off + 1 >= (unsigned)(screen_Rows * screen_Columns))
return;
if (row == screen_Rows - 1 && col >= screen_Columns - 2)
{
ScreenAttrs[off] = (sattr_T)-1;
return;
}
screen_char(off, row, col);
out_char(ScreenLines[off + 1]);
++screen_cur_col;
}
#endif
void
screen_draw_rectangle(
int row,
int col,
int height,
int width,
int invert)
{
int r, c;
int off;
#ifdef FEAT_MBYTE
int max_off;
#endif
if (ScreenLines == NULL)
return;
if (invert)
screen_char_attr = HL_INVERSE;
for (r = row; r < row + height; ++r)
{
off = LineOffset[r];
#ifdef FEAT_MBYTE
max_off = off + screen_Columns;
#endif
for (c = col; c < col + width; ++c)
{
#ifdef FEAT_MBYTE
if (enc_dbcs != 0 && dbcs_off2cells(off + c, max_off) > 1)
{
screen_char_2(off + c, r, c);
++c;
}
else
#endif
{
screen_char(off + c, r, c);
#ifdef FEAT_MBYTE
if (utf_off2cells(off + c, max_off) > 1)
++c;
#endif
}
}
}
screen_char_attr = 0;
}
static void
redraw_block(int row, int end, win_T *wp)
{
int col;
int width;
# ifdef FEAT_CLIPBOARD
clip_may_clear_selection(row, end - 1);
# endif
if (wp == NULL)
{
col = 0;
width = Columns;
}
else
{
col = wp->w_wincol;
width = wp->w_width;
}
screen_draw_rectangle(row, col, end - row, width, FALSE);
}
static void
space_to_screenline(int off, int attr)
{
ScreenLines[off] = ' ';
ScreenAttrs[off] = attr;
# ifdef FEAT_MBYTE
if (enc_utf8)
ScreenLinesUC[off] = 0;
# endif
}
void
screen_fill(
int start_row,
int end_row,
int start_col,
int end_col,
int c1,
int c2,
int attr)
{
int row;
int col;
int off;
int end_off;
int did_delete;
int c;
int norm_term;
#if defined(FEAT_GUI) || defined(UNIX)
int force_next = FALSE;
#endif
if (end_row > screen_Rows)
end_row = screen_Rows;
if (end_col > screen_Columns)
end_col = screen_Columns;
if (ScreenLines == NULL
|| start_row >= end_row
|| start_col >= end_col)
return;
norm_term = (
#ifdef FEAT_GUI
!gui.in_use &&
#endif
!IS_CTERM);
for (row = start_row; row < end_row; ++row)
{
#ifdef FEAT_MBYTE
if (has_mbyte
# ifdef FEAT_GUI
&& !gui.in_use
# endif
)
{
if (start_col > 0 && mb_fix_col(start_col, row) != start_col)
screen_puts_len((char_u *)" ", 1, row, start_col - 1, 0);
if (end_col < screen_Columns && mb_fix_col(end_col, row) != end_col)
screen_puts_len((char_u *)" ", 1, row, end_col, 0);
}
#endif
did_delete = FALSE;
if (c2 == ' '
&& end_col == Columns
&& can_clear(T_CE)
&& (attr == 0
|| (norm_term
&& attr <= HL_ALL
&& ((attr & ~(HL_BOLD | HL_ITALIC)) == 0))))
{
col = start_col;
if (c1 != ' ')
++col;
off = LineOffset[row] + col;
end_off = LineOffset[row] + end_col;
#ifdef FEAT_MBYTE
if (enc_utf8)
while (off < end_off && ScreenLines[off] == ' '
&& ScreenAttrs[off] == 0 && ScreenLinesUC[off] == 0)
++off;
else
#endif
while (off < end_off && ScreenLines[off] == ' '
&& ScreenAttrs[off] == 0)
++off;
if (off < end_off)
{
col = off - LineOffset[row];
screen_stop_highlight();
term_windgoto(row, col);
out_str(T_CE);
screen_start();
col = end_col - col;
while (col--)
{
space_to_screenline(off, 0);
++off;
}
}
did_delete = TRUE;
}
off = LineOffset[row] + start_col;
c = c1;
for (col = start_col; col < end_col; ++col)
{
if (ScreenLines[off] != c
#ifdef FEAT_MBYTE
|| (enc_utf8 && (int)ScreenLinesUC[off]
!= (c >= 0x80 ? c : 0))
#endif
|| ScreenAttrs[off] != attr
#if defined(FEAT_GUI) || defined(UNIX)
|| force_next
#endif
)
{
#if defined(FEAT_GUI) || defined(UNIX)
if (
# ifdef FEAT_GUI
gui.in_use
# endif
# if defined(FEAT_GUI) && defined(UNIX)
||
# endif
# ifdef UNIX
term_is_xterm
# endif
)
{
if (ScreenLines[off] != ' '
&& (ScreenAttrs[off] > HL_ALL
|| ScreenAttrs[off] & HL_BOLD))
force_next = TRUE;
else
force_next = FALSE;
}
#endif
ScreenLines[off] = c;
#ifdef FEAT_MBYTE
if (enc_utf8)
{
if (c >= 0x80)
{
ScreenLinesUC[off] = c;
ScreenLinesC[0][off] = 0;
}
else
ScreenLinesUC[off] = 0;
}
#endif
ScreenAttrs[off] = attr;
if (!did_delete || c != ' ')
screen_char(off, row, col);
}
++off;
if (col == start_col)
{
if (did_delete)
break;
c = c2;
}
}
if (end_col == Columns)
LineWraps[row] = FALSE;
if (row == Rows - 1)
{
redraw_cmdline = TRUE;
if (c1 == ' ' && c2 == ' ')
clear_cmdline = FALSE;
if (start_col == 0)
mode_displayed = FALSE;
}
}
}
void
check_for_delay(int check_msg_scroll)
{
if ((emsg_on_display || (check_msg_scroll && msg_scroll))
&& !did_wait_return
&& emsg_silent == 0)
{
out_flush();
ui_delay(1000L, TRUE);
emsg_on_display = FALSE;
if (check_msg_scroll)
msg_scroll = FALSE;
}
}
int
screen_valid(int doclear)
{
screenalloc(doclear);
return (ScreenLines != NULL);
}
void
screenalloc(int doclear)
{
int new_row, old_row;
#ifdef FEAT_GUI
int old_Rows;
#endif
win_T *wp;
int outofmem = FALSE;
int len;
schar_T *new_ScreenLines;
#ifdef FEAT_MBYTE
u8char_T *new_ScreenLinesUC = NULL;
u8char_T *new_ScreenLinesC[MAX_MCO];
schar_T *new_ScreenLines2 = NULL;
int i;
#endif
sattr_T *new_ScreenAttrs;
unsigned *new_LineOffset;
char_u *new_LineWraps;
short *new_TabPageIdxs;
tabpage_T *tp;
static int entered = FALSE;
static int done_outofmem_msg = FALSE;
#ifdef FEAT_AUTOCMD
int retry_count = 0;
retry:
#endif
if ((ScreenLines != NULL
&& Rows == screen_Rows
&& Columns == screen_Columns
#ifdef FEAT_MBYTE
&& enc_utf8 == (ScreenLinesUC != NULL)
&& (enc_dbcs == DBCS_JPNU) == (ScreenLines2 != NULL)
&& p_mco == Screen_mco
#endif
)
|| Rows == 0
|| Columns == 0
|| (!full_screen && ScreenLines == NULL))
return;
if (entered)
return;
entered = TRUE;
++RedrawingDisabled;
win_new_shellsize();
comp_col();
FOR_ALL_TAB_WINDOWS(tp, wp)
win_free_lsize(wp);
#ifdef FEAT_AUTOCMD
if (aucmd_win != NULL)
win_free_lsize(aucmd_win);
#endif
new_ScreenLines = (schar_T *)lalloc((long_u)(
(Rows + 1) * Columns * sizeof(schar_T)), FALSE);
#ifdef FEAT_MBYTE
vim_memset(new_ScreenLinesC, 0, sizeof(u8char_T *) * MAX_MCO);
if (enc_utf8)
{
new_ScreenLinesUC = (u8char_T *)lalloc((long_u)(
(Rows + 1) * Columns * sizeof(u8char_T)), FALSE);
for (i = 0; i < p_mco; ++i)
new_ScreenLinesC[i] = (u8char_T *)lalloc_clear((long_u)(
(Rows + 1) * Columns * sizeof(u8char_T)), FALSE);
}
if (enc_dbcs == DBCS_JPNU)
new_ScreenLines2 = (schar_T *)lalloc((long_u)(
(Rows + 1) * Columns * sizeof(schar_T)), FALSE);
#endif
new_ScreenAttrs = (sattr_T *)lalloc((long_u)(
(Rows + 1) * Columns * sizeof(sattr_T)), FALSE);
new_LineOffset = (unsigned *)lalloc((long_u)(
Rows * sizeof(unsigned)), FALSE);
new_LineWraps = (char_u *)lalloc((long_u)(Rows * sizeof(char_u)), FALSE);
new_TabPageIdxs = (short *)lalloc((long_u)(Columns * sizeof(short)), FALSE);
FOR_ALL_TAB_WINDOWS(tp, wp)
{
if (win_alloc_lines(wp) == FAIL)
{
outofmem = TRUE;
goto give_up;
}
}
#ifdef FEAT_AUTOCMD
if (aucmd_win != NULL && aucmd_win->w_lines == NULL
&& win_alloc_lines(aucmd_win) == FAIL)
outofmem = TRUE;
#endif
give_up:
#ifdef FEAT_MBYTE
for (i = 0; i < p_mco; ++i)
if (new_ScreenLinesC[i] == NULL)
break;
#endif
if (new_ScreenLines == NULL
#ifdef FEAT_MBYTE
|| (enc_utf8 && (new_ScreenLinesUC == NULL || i != p_mco))
|| (enc_dbcs == DBCS_JPNU && new_ScreenLines2 == NULL)
#endif
|| new_ScreenAttrs == NULL
|| new_LineOffset == NULL
|| new_LineWraps == NULL
|| new_TabPageIdxs == NULL
|| outofmem)
{
if (ScreenLines != NULL || !done_outofmem_msg)
{
do_outofmem_msg((long_u)((Rows + 1) * Columns));
done_outofmem_msg = TRUE;
}
vim_free(new_ScreenLines);
new_ScreenLines = NULL;
#ifdef FEAT_MBYTE
vim_free(new_ScreenLinesUC);
new_ScreenLinesUC = NULL;
for (i = 0; i < p_mco; ++i)
{
vim_free(new_ScreenLinesC[i]);
new_ScreenLinesC[i] = NULL;
}
vim_free(new_ScreenLines2);
new_ScreenLines2 = NULL;
#endif
vim_free(new_ScreenAttrs);
new_ScreenAttrs = NULL;
vim_free(new_LineOffset);
new_LineOffset = NULL;
vim_free(new_LineWraps);
new_LineWraps = NULL;
vim_free(new_TabPageIdxs);
new_TabPageIdxs = NULL;
}
else
{
done_outofmem_msg = FALSE;
for (new_row = 0; new_row < Rows; ++new_row)
{
new_LineOffset[new_row] = new_row * Columns;
new_LineWraps[new_row] = FALSE;
if (!doclear)
{
(void)vim_memset(new_ScreenLines + new_row * Columns,
' ', (size_t)Columns * sizeof(schar_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
(void)vim_memset(new_ScreenLinesUC + new_row * Columns,
0, (size_t)Columns * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
(void)vim_memset(new_ScreenLinesC[i]
+ new_row * Columns,
0, (size_t)Columns * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
(void)vim_memset(new_ScreenLines2 + new_row * Columns,
0, (size_t)Columns * sizeof(schar_T));
#endif
(void)vim_memset(new_ScreenAttrs + new_row * Columns,
0, (size_t)Columns * sizeof(sattr_T));
old_row = new_row + (screen_Rows - Rows);
if (old_row >= 0 && ScreenLines != NULL)
{
if (screen_Columns < Columns)
len = screen_Columns;
else
len = Columns;
#ifdef FEAT_MBYTE
if (!(enc_utf8 && ScreenLinesUC == NULL)
&& p_mco == Screen_mco)
#endif
mch_memmove(new_ScreenLines + new_LineOffset[new_row],
ScreenLines + LineOffset[old_row],
(size_t)len * sizeof(schar_T));
#ifdef FEAT_MBYTE
if (enc_utf8 && ScreenLinesUC != NULL
&& p_mco == Screen_mco)
{
mch_memmove(new_ScreenLinesUC + new_LineOffset[new_row],
ScreenLinesUC + LineOffset[old_row],
(size_t)len * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(new_ScreenLinesC[i]
+ new_LineOffset[new_row],
ScreenLinesC[i] + LineOffset[old_row],
(size_t)len * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU && ScreenLines2 != NULL)
mch_memmove(new_ScreenLines2 + new_LineOffset[new_row],
ScreenLines2 + LineOffset[old_row],
(size_t)len * sizeof(schar_T));
#endif
mch_memmove(new_ScreenAttrs + new_LineOffset[new_row],
ScreenAttrs + LineOffset[old_row],
(size_t)len * sizeof(sattr_T));
}
}
}
current_ScreenLine = new_ScreenLines + Rows * Columns;
}
free_screenlines();
ScreenLines = new_ScreenLines;
#ifdef FEAT_MBYTE
ScreenLinesUC = new_ScreenLinesUC;
for (i = 0; i < p_mco; ++i)
ScreenLinesC[i] = new_ScreenLinesC[i];
Screen_mco = p_mco;
ScreenLines2 = new_ScreenLines2;
#endif
ScreenAttrs = new_ScreenAttrs;
LineOffset = new_LineOffset;
LineWraps = new_LineWraps;
TabPageIdxs = new_TabPageIdxs;
#ifdef FEAT_GUI
old_Rows = screen_Rows;
#endif
screen_Rows = Rows;
screen_Columns = Columns;
must_redraw = CLEAR;
if (doclear)
screenclear2();
#ifdef FEAT_GUI
else if (gui.in_use
&& !gui.starting
&& ScreenLines != NULL
&& old_Rows != Rows)
{
(void)gui_redraw_block(0, 0, (int)Rows - 1, (int)Columns - 1, 0);
if (msg_row >= Rows)
msg_row = Rows - 1;
else if (Rows > old_Rows)
msg_row += Rows - old_Rows;
if (msg_col >= Columns)
msg_col = Columns - 1;
}
#endif
entered = FALSE;
--RedrawingDisabled;
#ifdef FEAT_AUTOCMD
if (starting == 0 && ++retry_count <= 3)
{
apply_autocmds(EVENT_VIMRESIZED, NULL, NULL, FALSE, curbuf);
goto retry;
}
#endif
}
void
free_screenlines(void)
{
#ifdef FEAT_MBYTE
int i;
vim_free(ScreenLinesUC);
for (i = 0; i < Screen_mco; ++i)
vim_free(ScreenLinesC[i]);
vim_free(ScreenLines2);
#endif
vim_free(ScreenLines);
vim_free(ScreenAttrs);
vim_free(LineOffset);
vim_free(LineWraps);
vim_free(TabPageIdxs);
}
void
screenclear(void)
{
check_for_delay(FALSE);
screenalloc(FALSE);
screenclear2();
}
static void
screenclear2(void)
{
int i;
if (starting == NO_SCREEN || ScreenLines == NULL
#ifdef FEAT_GUI
|| (gui.in_use && gui.starting)
#endif
)
return;
#ifdef FEAT_GUI
if (!gui.in_use)
#endif
screen_attr = -1;
screen_stop_highlight();
#ifdef FEAT_CLIPBOARD
clip_scroll_selection(9999);
#endif
for (i = 0; i < Rows; ++i)
{
lineclear(LineOffset[i], (int)Columns, 0);
LineWraps[i] = FALSE;
}
if (can_clear(T_CL))
{
out_str(T_CL);
clear_cmdline = FALSE;
mode_displayed = FALSE;
}
else
{
for (i = 0; i < Rows; ++i)
lineinvalid(LineOffset[i], (int)Columns);
clear_cmdline = TRUE;
}
screen_cleared = TRUE;
win_rest_invalid(firstwin);
redraw_cmdline = TRUE;
redraw_tabline = TRUE;
if (must_redraw == CLEAR)
must_redraw = NOT_VALID;
compute_cmdrow();
msg_row = cmdline_row;
msg_col = 0;
screen_start();
msg_scrolled = 0;
msg_didany = FALSE;
msg_didout = FALSE;
}
static void
lineclear(unsigned off, int width, int attr)
{
(void)vim_memset(ScreenLines + off, ' ', (size_t)width * sizeof(schar_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
(void)vim_memset(ScreenLinesUC + off, 0,
(size_t)width * sizeof(u8char_T));
#endif
(void)vim_memset(ScreenAttrs + off, attr, (size_t)width * sizeof(sattr_T));
}
static void
lineinvalid(unsigned off, int width)
{
(void)vim_memset(ScreenAttrs + off, -1, (size_t)width * sizeof(sattr_T));
}
static void
linecopy(int to, int from, win_T *wp)
{
unsigned off_to = LineOffset[to] + wp->w_wincol;
unsigned off_from = LineOffset[from] + wp->w_wincol;
mch_memmove(ScreenLines + off_to, ScreenLines + off_from,
wp->w_width * sizeof(schar_T));
#ifdef FEAT_MBYTE
if (enc_utf8)
{
int i;
mch_memmove(ScreenLinesUC + off_to, ScreenLinesUC + off_from,
wp->w_width * sizeof(u8char_T));
for (i = 0; i < p_mco; ++i)
mch_memmove(ScreenLinesC[i] + off_to, ScreenLinesC[i] + off_from,
wp->w_width * sizeof(u8char_T));
}
if (enc_dbcs == DBCS_JPNU)
mch_memmove(ScreenLines2 + off_to, ScreenLines2 + off_from,
wp->w_width * sizeof(schar_T));
#endif
mch_memmove(ScreenAttrs + off_to, ScreenAttrs + off_from,
wp->w_width * sizeof(sattr_T));
}
int
can_clear(char_u *p)
{
return (*p != NUL && (t_colors <= 1
#ifdef FEAT_GUI
|| gui.in_use
#endif
#ifdef FEAT_TERMGUICOLORS
|| (p_tgc && cterm_normal_bg_gui_color == INVALCOLOR)
|| (!p_tgc && cterm_normal_bg_color == 0)
#else
|| cterm_normal_bg_color == 0
#endif
|| *T_UT != NUL));
}
void
screen_start(void)
{
screen_cur_row = screen_cur_col = 9999;
}
void
windgoto(int row, int col)
{
sattr_T *p;
int i;
int plan;
int cost;
int wouldbe_col;
int noinvcurs;
char_u *bs;
int goto_cost;
int attr;
#define GOTO_COST 7
#define HIGHL_COST 5
#define PLAN_LE 1
#define PLAN_CR 2
#define PLAN_NL 3
#define PLAN_WRITE 4
if (ScreenLines == NULL)
return;
if (col != screen_cur_col || row != screen_cur_row)
{
if (row < 0)
row = 0;
if (row >= screen_Rows)
row = screen_Rows - 1;
if (col >= screen_Columns)
col = screen_Columns - 1;
if (screen_attr && *T_MS == NUL)
noinvcurs = HIGHL_COST;
else
noinvcurs = 0;
goto_cost = GOTO_COST + noinvcurs;
if (row >= screen_cur_row && screen_cur_col < Columns)
{
bs = NULL;
attr = screen_attr;
if (row == screen_cur_row && col < screen_cur_col)
{
if (*T_LE)
bs = T_LE;
else
bs = T_BC;
if (*bs)
cost = (screen_cur_col - col) * (int)STRLEN(bs);
else
cost = 999;
if (col + 1 < cost)
{
plan = PLAN_CR;
wouldbe_col = 0;
cost = 1;
}
else
{
plan = PLAN_LE;
wouldbe_col = col;
}
if (noinvcurs)
{
cost += noinvcurs;
attr = 0;
}
}
else if (row > screen_cur_row)
{
plan = PLAN_NL;
wouldbe_col = 0;
cost = (row - screen_cur_row) * 2;
if (noinvcurs)
{
cost += noinvcurs;
attr = 0;
}
}
else
{
plan = PLAN_WRITE;
wouldbe_col = screen_cur_col;
cost = 0;
}
i = col - wouldbe_col;
if (i > 0)
cost += i;
if (cost < goto_cost && i > 0)
{
p = ScreenAttrs + LineOffset[row] + wouldbe_col;
while (i && *p++ == attr)
--i;
if (i != 0)
{
if (*--p == 0)
{
cost += noinvcurs;
while (i && *p++ == 0)
--i;
}
if (i != 0)
cost = 999;
}
#ifdef FEAT_MBYTE
if (enc_utf8)
{
for (i = wouldbe_col; i < col; ++i)
if (ScreenLinesUC[LineOffset[row] + i] != 0)
{
cost = 999;
break;
}
}
#endif
}
if (cost < goto_cost)
{
if (plan == PLAN_LE)
{
if (noinvcurs)
screen_stop_highlight();
while (screen_cur_col > col)
{
out_str(bs);
--screen_cur_col;
}
}
else if (plan == PLAN_CR)
{
if (noinvcurs)
screen_stop_highlight();
out_char('\r');
screen_cur_col = 0;
}
else if (plan == PLAN_NL)
{
if (noinvcurs)
screen_stop_highlight();
while (screen_cur_row < row)
{
out_char('\n');
++screen_cur_row;
}
screen_cur_col = 0;
}
i = col - screen_cur_col;
if (i > 0)
{
if (T_ND[0] != NUL && T_ND[1] == NUL)
{
while (i-- > 0)
out_char(*T_ND);
}
else
{
int off;
off = LineOffset[row] + screen_cur_col;
while (i-- > 0)
{
if (ScreenAttrs[off] != screen_attr)
screen_stop_highlight();
#ifdef FEAT_MBYTE
out_flush_check();
#endif
out_char(ScreenLines[off]);
#ifdef FEAT_MBYTE
if (enc_dbcs == DBCS_JPNU
&& ScreenLines[off] == 0x8e)
out_char(ScreenLines2[off]);
#endif
++off;
}
}
}
}
}
else
cost = 999;
if (cost >= goto_cost)
{
if (noinvcurs)
screen_stop_highlight();
if (row == screen_cur_row && (col > screen_cur_col)
&& *T_CRI != NUL)
term_cursor_right(col - screen_cur_col);
else
term_windgoto(row, col);
}
screen_cur_row = row;
screen_cur_col = col;
}
}
void
setcursor(void)
{
if (redrawing())
{
validate_cursor();
windgoto(W_WINROW(curwin) + curwin->w_wrow,
curwin->w_wincol + (
#ifdef FEAT_RIGHTLEFT
curwin->w_p_rl ? ((int)curwin->w_width - curwin->w_wcol - (
# ifdef FEAT_MBYTE
(has_mbyte
&& (*mb_ptr2cells)(ml_get_cursor()) == 2
&& vim_isprintc(gchar_cursor())) ? 2 :
# endif
1)) :
#endif
curwin->w_wcol));
}
}
int
win_ins_lines(
win_T *wp,
int row,
int line_count,
int invalid,
int mayclear)
{
int did_delete;
int nextrow;
int lastrow;
int retval;
if (invalid)
wp->w_lines_valid = 0;
if (wp->w_height < 5)
return FAIL;
if (line_count > wp->w_height - row)
line_count = wp->w_height - row;
retval = win_do_lines(wp, row, line_count, mayclear, FALSE, 0);
if (retval != MAYBE)
return retval;
did_delete = FALSE;
if (wp->w_next != NULL || wp->w_status_height)
{
if (screen_del_lines(0, W_WINROW(wp) + wp->w_height - line_count,
line_count, (int)Rows, FALSE, 0, NULL) == OK)
did_delete = TRUE;
else if (wp->w_next)
return FAIL;
}
if (!did_delete)
{
wp->w_redr_status = TRUE;
redraw_cmdline = TRUE;
nextrow = W_WINROW(wp) + wp->w_height + wp->w_status_height;
lastrow = nextrow + line_count;
if (lastrow > Rows)
lastrow = Rows;
screen_fill(nextrow - line_count, lastrow - line_count,
wp->w_wincol, (int)W_ENDCOL(wp),
' ', ' ', 0);
}
if (screen_ins_lines(0, W_WINROW(wp) + row, line_count, (int)Rows, 0, NULL)
== FAIL)
{
if (did_delete)
{
wp->w_redr_status = TRUE;
win_rest_invalid(W_NEXT(wp));
}
return FAIL;
}
return OK;
}
int
win_del_lines(
win_T *wp,
int row,
int line_count,
int invalid,
int mayclear,
int clear_attr)
{
int retval;
if (invalid)
wp->w_lines_valid = 0;
if (line_count > wp->w_height - row)
line_count = wp->w_height - row;
retval = win_do_lines(wp, row, line_count, mayclear, TRUE, clear_attr);
if (retval != MAYBE)
return retval;
if (screen_del_lines(0, W_WINROW(wp) + row, line_count,
(int)Rows, FALSE, clear_attr, NULL) == FAIL)
return FAIL;
if (wp->w_next || wp->w_status_height || cmdline_row < Rows - 1)
{
if (screen_ins_lines(0, W_WINROW(wp) + wp->w_height - line_count,
line_count, (int)Rows, clear_attr, NULL) == FAIL)
{
wp->w_redr_status = TRUE;
win_rest_invalid(wp->w_next);
}
}
else
redraw_cmdline = TRUE;
return OK;
}
static int
win_do_lines(
win_T *wp,
int row,
int line_count,
int mayclear,
int del,
int clear_attr)
{
int retval;
if (!redrawing() || line_count <= 0)
return FAIL;
if (no_win_do_lines_ins && !del)
return FAIL;
if (mayclear && Rows - line_count < 5 && wp->w_width == Columns)
{
if (!no_win_do_lines_ins)
screenclear();
return FAIL;
}
if (row + line_count >= wp->w_height)
{
screen_fill(W_WINROW(wp) + row, W_WINROW(wp) + wp->w_height,
wp->w_wincol, (int)W_ENDCOL(wp),
' ', ' ', 0);
return OK;
}
if (!no_win_do_lines_ins)
clear_cmdline = TRUE;
if (scroll_region || wp->w_width != Columns)
{
if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
scroll_region_set(wp, row);
if (del)
retval = screen_del_lines(W_WINROW(wp) + row, 0, line_count,
wp->w_height - row, FALSE, clear_attr, wp);
else
retval = screen_ins_lines(W_WINROW(wp) + row, 0, line_count,
wp->w_height - row, clear_attr, wp);
if (scroll_region && (wp->w_width == Columns || *T_CSV != NUL))
scroll_region_reset();
return retval;
}
if (wp->w_next != NULL && p_tf)
return FAIL;
return MAYBE;
}
static void
win_rest_invalid(win_T *wp)
{
while (wp != NULL)
{
redraw_win_later(wp, NOT_VALID);
wp->w_redr_status = TRUE;
wp = wp->w_next;
}
redraw_cmdline = TRUE;
}
#define USE_T_CAL 1
#define USE_T_CDL 2
#define USE_T_AL 3
#define USE_T_CE 4
#define USE_T_DL 5
#define USE_T_SR 6
#define USE_NL 7
#define USE_T_CD 8
#define USE_REDRAW 9
int
screen_ins_lines(
int off,
int row,
int line_count,
int end,
int clear_attr,
win_T *wp)
{
int i;
int j;
unsigned temp;
int cursor_row;
int type;
int result_empty;
int can_ce = can_clear(T_CE);
if (!screen_valid(TRUE) || line_count <= 0 || line_count > p_ttyscroll
#ifdef FEAT_CLIPBOARD
|| (clip_star.state != SELECT_CLEARED
&& redrawing_for_callback > 0)
#endif
)
return FAIL;
result_empty = (row + line_count >= end);
if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
type = USE_REDRAW;
else if (can_clear(T_CD) && result_empty)
type = USE_T_CD;
else if (*T_CAL != NUL && (line_count > 1 || *T_AL == NUL))
type = USE_T_CAL;
else if (*T_CDL != NUL && result_empty && (line_count > 1 || !can_ce))
type = USE_T_CDL;
else if (*T_AL != NUL)
type = USE_T_AL;
else if (can_ce && result_empty)
type = USE_T_CE;
else if (*T_DL != NUL && result_empty)
type = USE_T_DL;
else if (*T_SR != NUL && row == 0 && (*T_DA == NUL || can_ce))
type = USE_T_SR;
else
return FAIL;
if (type == USE_T_CD || type == USE_T_CDL ||
type == USE_T_CE || type == USE_T_DL)
return screen_del_lines(off, row, line_count, end, FALSE, 0, wp);
if (*T_DB)
screen_del_lines(off, end - line_count, line_count, end, FALSE, 0, wp);
#ifdef FEAT_CLIPBOARD
if (off + row > 0 || (wp != NULL && wp->w_width != Columns))
clip_clear_selection(&clip_star);
else
clip_scroll_selection(-line_count);
#endif
#ifdef FEAT_GUI
gui_dont_update_cursor(row + off <= gui.cursor_row);
#endif
if (*T_CCS != NUL)
cursor_row = row;
else
cursor_row = row + off;
row += off;
end += off;
for (i = 0; i < line_count; ++i)
{
if (wp != NULL && wp->w_width != Columns)
{
j = end - 1 - i;
while ((j -= line_count) >= row)
linecopy(j + line_count, j, wp);
j += line_count;
if (can_clear((char_u *)" "))
lineclear(LineOffset[j] + wp->w_wincol, wp->w_width,
clear_attr);
else
lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
LineWraps[j] = FALSE;
}
else
{
j = end - 1 - i;
temp = LineOffset[j];
while ((j -= line_count) >= row)
{
LineOffset[j + line_count] = LineOffset[j];
LineWraps[j + line_count] = LineWraps[j];
}
LineOffset[j + line_count] = temp;
LineWraps[j + line_count] = FALSE;
if (can_clear((char_u *)" "))
lineclear(temp, (int)Columns, clear_attr);
else
lineinvalid(temp, (int)Columns);
}
}
screen_stop_highlight();
windgoto(cursor_row, 0);
if (clear_attr != 0)
screen_start_highlight(clear_attr);
if (type == USE_REDRAW)
redraw_block(row, end, wp);
else if (type == USE_T_CAL)
{
term_append_lines(line_count);
screen_start();
}
else
{
for (i = 0; i < line_count; i++)
{
if (type == USE_T_AL)
{
if (i && cursor_row != 0)
windgoto(cursor_row, 0);
out_str(T_AL);
}
else
out_str(T_SR);
screen_start();
}
}
if (type == USE_T_SR && *T_DA)
{
for (i = 0; i < line_count; ++i)
{
windgoto(off + i, 0);
out_str(T_CE);
screen_start();
}
}
#ifdef FEAT_GUI
gui_can_update_cursor();
if (gui.in_use)
out_flush();
#endif
return OK;
}
int
screen_del_lines(
int off,
int row,
int line_count,
int end,
int force,
int clear_attr,
win_T *wp UNUSED)
{
int j;
int i;
unsigned temp;
int cursor_row;
int cursor_end;
int result_empty;
int can_delete;
int type;
if (!screen_valid(TRUE) || line_count <= 0
|| (!force && line_count > p_ttyscroll)
#ifdef FEAT_CLIPBOARD
|| (clip_star.state != SELECT_CLEARED
&& redrawing_for_callback > 0)
#endif
)
return FAIL;
result_empty = row + line_count >= end;
can_delete = (*T_DB == NUL || can_clear(T_CE));
if (wp != NULL && wp->w_width != Columns && *T_CSV == NUL)
type = USE_REDRAW;
else if (can_clear(T_CD) && result_empty)
type = USE_T_CD;
#if defined(__BEOS__) && defined(BEOS_DR8)
else if (row == 0 && T_DB == empty_option
&& (line_count == 1 || *T_CDL == NUL))
#else
else if (row == 0 && (
#ifndef AMIGA
line_count == 1 ||
#endif
*T_CDL == NUL))
#endif
type = USE_NL;
else if (*T_CDL != NUL && line_count > 1 && can_delete)
type = USE_T_CDL;
else if (can_clear(T_CE) && result_empty
&& (wp == NULL || wp->w_width == Columns))
type = USE_T_CE;
else if (*T_DL != NUL && can_delete)
type = USE_T_DL;
else if (*T_CDL != NUL && can_delete)
type = USE_T_CDL;
else
return FAIL;
#ifdef FEAT_CLIPBOARD
if (off + row > 0 || (wp != NULL && wp->w_width != Columns))
clip_clear_selection(&clip_star);
else
clip_scroll_selection(line_count);
#endif
#ifdef FEAT_GUI
gui_dont_update_cursor(gui.cursor_row >= row + off
&& gui.cursor_row < end + off);
#endif
if (*T_CCS != NUL)
{
cursor_row = row;
cursor_end = end;
}
else
{
cursor_row = row + off;
cursor_end = end + off;
}
row += off;
end += off;
for (i = 0; i < line_count; ++i)
{
if (wp != NULL && wp->w_width != Columns)
{
j = row + i;
while ((j += line_count) <= end - 1)
linecopy(j - line_count, j, wp);
j -= line_count;
if (can_clear((char_u *)" "))
lineclear(LineOffset[j] + wp->w_wincol, wp->w_width,
clear_attr);
else
lineinvalid(LineOffset[j] + wp->w_wincol, wp->w_width);
LineWraps[j] = FALSE;
}
else
{
j = row + i;
temp = LineOffset[j];
while ((j += line_count) <= end - 1)
{
LineOffset[j - line_count] = LineOffset[j];
LineWraps[j - line_count] = LineWraps[j];
}
LineOffset[j - line_count] = temp;
LineWraps[j - line_count] = FALSE;
if (can_clear((char_u *)" "))
lineclear(temp, (int)Columns, clear_attr);
else
lineinvalid(temp, (int)Columns);
}
}
if (screen_attr != clear_attr)
screen_stop_highlight();
if (clear_attr != 0)
screen_start_highlight(clear_attr);
if (type == USE_REDRAW)
redraw_block(row, end, wp);
else if (type == USE_T_CD)
{
windgoto(cursor_row, 0);
out_str(T_CD);
screen_start();
}
else if (type == USE_T_CDL)
{
windgoto(cursor_row, 0);
term_delete_lines(line_count);
screen_start();
}
else if (type == USE_NL)
{
windgoto(cursor_end - 1, 0);
for (i = line_count; --i >= 0; )
out_char('\n');
}
else
{
for (i = line_count; --i >= 0; )
{
if (type == USE_T_DL)
{
windgoto(cursor_row, 0);
out_str(T_DL);
}
else
{
windgoto(cursor_row + i, 0);
out_str(T_CE);
}
screen_start();
}
}
if (*T_DB && (type == USE_T_DL || type == USE_T_CDL))
{
for (i = line_count; i > 0; --i)
{
windgoto(cursor_end - i, 0);
out_str(T_CE);
screen_start();
}
}
#ifdef FEAT_GUI
gui_can_update_cursor();
if (gui.in_use)
out_flush();
#endif
return OK;
}
int
showmode(void)
{
int need_clear;
int length = 0;
int do_mode;
int attr;
int nwr_save;
#ifdef FEAT_INS_EXPAND
int sub_attr;
#endif
do_mode = ((p_smd && msg_silent == 0)
&& ((State & INSERT)
|| restart_edit
|| VIsual_active));
if (do_mode || Recording)
{
if (!redrawing() || (char_avail() && !KeyTyped) || msg_silent != 0)
{
redraw_cmdline = TRUE;
return 0;
}
nwr_save = need_wait_return;
check_for_delay(FALSE);
need_clear = clear_cmdline;
if (clear_cmdline && cmdline_row < Rows - 1)
msg_clr_cmdline();
msg_pos_mode();
cursor_off();
attr = HL_ATTR(HLF_CM);
if (do_mode)
{
MSG_PUTS_ATTR("--", attr);
#if defined(FEAT_XIM)
if (
# ifdef FEAT_GUI_GTK
preedit_get_status()
# else
im_get_status()
# endif
)
# ifdef FEAT_GUI_GTK
MSG_PUTS_ATTR(" IM", attr);
# else
MSG_PUTS_ATTR(" XIM", attr);
# endif
#endif
#if defined(FEAT_HANGULIN) && defined(FEAT_GUI)
if (gui.in_use)
{
if (hangul_input_state_get())
{
if (enc_utf8)
MSG_PUTS_ATTR(" \355\225\234\352\270\200", attr);
else
MSG_PUTS_ATTR(" \307\321\261\333", attr);
}
}
#endif
#ifdef FEAT_INS_EXPAND
if (edit_submode != NULL && !shortmess(SHM_COMPLETIONMENU))
{
length = (Rows - msg_row) * Columns - 3;
if (edit_submode_extra != NULL)
length -= vim_strsize(edit_submode_extra);
if (length > 0)
{
if (edit_submode_pre != NULL)
length -= vim_strsize(edit_submode_pre);
if (length - vim_strsize(edit_submode) > 0)
{
if (edit_submode_pre != NULL)
msg_puts_attr(edit_submode_pre, attr);
msg_puts_attr(edit_submode, attr);
}
if (edit_submode_extra != NULL)
{
MSG_PUTS_ATTR(" ", attr);
if ((int)edit_submode_highl < (int)HLF_COUNT)
sub_attr = HL_ATTR(edit_submode_highl);
else
sub_attr = attr;
msg_puts_attr(edit_submode_extra, sub_attr);
}
}
length = 0;
}
else
#endif
{
#ifdef FEAT_VREPLACE
if (State & VREPLACE_FLAG)
MSG_PUTS_ATTR(_(" VREPLACE"), attr);
else
#endif
if (State & REPLACE_FLAG)
MSG_PUTS_ATTR(_(" REPLACE"), attr);
else if (State & INSERT)
{
#ifdef FEAT_RIGHTLEFT
if (p_ri)
MSG_PUTS_ATTR(_(" REVERSE"), attr);
#endif
MSG_PUTS_ATTR(_(" INSERT"), attr);
}
else if (restart_edit == 'I')
MSG_PUTS_ATTR(_(" (insert)"), attr);
else if (restart_edit == 'R')
MSG_PUTS_ATTR(_(" (replace)"), attr);
else if (restart_edit == 'V')
MSG_PUTS_ATTR(_(" (vreplace)"), attr);
#ifdef FEAT_RIGHTLEFT
if (p_hkmap)
MSG_PUTS_ATTR(_(" Hebrew"), attr);
# ifdef FEAT_FKMAP
if (p_fkmap)
MSG_PUTS_ATTR(farsi_text_5, attr);
# endif
#endif
#ifdef FEAT_KEYMAP
if (State & LANGMAP)
{
# ifdef FEAT_ARABIC
if (curwin->w_p_arab)
MSG_PUTS_ATTR(_(" Arabic"), attr);
else
# endif
if (get_keymap_str(curwin, (char_u *)" (%s)",
NameBuff, MAXPATHL))
MSG_PUTS_ATTR(NameBuff, attr);
}
#endif
if ((State & INSERT) && p_paste)
MSG_PUTS_ATTR(_(" (paste)"), attr);
if (VIsual_active)
{
char *p;
switch ((VIsual_select ? 4 : 0)
+ (VIsual_mode == Ctrl_V) * 2
+ (VIsual_mode == 'V'))
{
case 0: p = N_(" VISUAL"); break;
case 1: p = N_(" VISUAL LINE"); break;
case 2: p = N_(" VISUAL BLOCK"); break;
case 4: p = N_(" SELECT"); break;
case 5: p = N_(" SELECT LINE"); break;
default: p = N_(" SELECT BLOCK"); break;
}
MSG_PUTS_ATTR(_(p), attr);
}
MSG_PUTS_ATTR(" --", attr);
}
need_clear = TRUE;
}
if (Recording
#ifdef FEAT_INS_EXPAND
&& edit_submode == NULL
#endif
)
{
recording_mode(attr);
need_clear = TRUE;
}
mode_displayed = TRUE;
if (need_clear || clear_cmdline)
msg_clr_eos();
msg_didout = FALSE;
length = msg_col;
msg_col = 0;
need_wait_return = nwr_save;
}
else if (clear_cmdline && msg_silent == 0)
msg_clr_cmdline();
#ifdef FEAT_CMDL_INFO
if (VIsual_active)
clear_showcmd();
if (redrawing() && lastwin->w_status_height == 0)
win_redr_ruler(lastwin, TRUE);
#endif
redraw_cmdline = FALSE;
clear_cmdline = FALSE;
return length;
}
static void
msg_pos_mode(void)
{
msg_col = 0;
msg_row = Rows - 1;
}
void
unshowmode(int force)
{
if (!redrawing() || (!force && char_avail() && !KeyTyped))
redraw_cmdline = TRUE;
else
clearmode();
}
void
clearmode(void)
{
msg_pos_mode();
if (Recording)
recording_mode(HL_ATTR(HLF_CM));
msg_clr_eos();
}
static void
recording_mode(int attr)
{
MSG_PUTS_ATTR(_("recording"), attr);
if (!shortmess(SHM_RECORDING))
{
char_u s[4];
sprintf((char *)s, " @%c", Recording);
MSG_PUTS_ATTR(s, attr);
}
}
static void
draw_tabline(void)
{
int tabcount = 0;
tabpage_T *tp;
int tabwidth;
int col = 0;
int scol = 0;
int attr;
win_T *wp;
win_T *cwp;
int wincount;
int modified;
int c;
int len;
int attr_sel = HL_ATTR(HLF_TPS);
int attr_nosel = HL_ATTR(HLF_TP);
int attr_fill = HL_ATTR(HLF_TPF);
char_u *p;
int room;
int use_sep_chars = (t_colors < 8
#ifdef FEAT_GUI
&& !gui.in_use
#endif
#ifdef FEAT_TERMGUICOLORS
&& !p_tgc
#endif
);
if (ScreenLines == NULL)
return;
redraw_tabline = FALSE;
#ifdef FEAT_GUI_TABLINE
if (gui_use_tabline())
{
gui_update_tabline();
return;
}
#endif
if (tabline_height() < 1)
return;
#if defined(FEAT_STL_OPT)
for (scol = 0; scol < Columns; ++scol)
TabPageIdxs[scol] = 0;
if (*p_tal != NUL)
{
int saved_did_emsg = did_emsg;
did_emsg = FALSE;
win_redr_custom(NULL, FALSE);
if (did_emsg)
set_string_option_direct((char_u *)"tabline", -1,
(char_u *)"", OPT_FREE, SID_ERROR);
did_emsg |= saved_did_emsg;
}
else
#endif
{
FOR_ALL_TABPAGES(tp)
++tabcount;
tabwidth = (Columns - 1 + tabcount / 2) / tabcount;
if (tabwidth < 6)
tabwidth = 6;
attr = attr_nosel;
tabcount = 0;
scol = 0;
for (tp = first_tabpage; tp != NULL && col < Columns - 4;
tp = tp->tp_next)
{
scol = col;
if (tp->tp_topframe == topframe)
attr = attr_sel;
if (use_sep_chars && col > 0)
screen_putchar('|', 0, col++, attr);
if (tp->tp_topframe != topframe)
attr = attr_nosel;
screen_putchar(' ', 0, col++, attr);
if (tp == curtab)
{
cwp = curwin;
wp = firstwin;
}
else
{
cwp = tp->tp_curwin;
wp = tp->tp_firstwin;
}
modified = FALSE;
for (wincount = 0; wp != NULL; wp = wp->w_next, ++wincount)
if (bufIsChanged(wp->w_buffer))
modified = TRUE;
if (modified || wincount > 1)
{
if (wincount > 1)
{
vim_snprintf((char *)NameBuff, MAXPATHL, "%d", wincount);
len = (int)STRLEN(NameBuff);
if (col + len >= Columns - 3)
break;
screen_puts_len(NameBuff, len, 0, col,
#if defined(FEAT_SYN_HL)
hl_combine_attr(attr, HL_ATTR(HLF_T))
#else
attr
#endif
);
col += len;
}
if (modified)
screen_puts_len((char_u *)"+", 1, 0, col++, attr);
screen_putchar(' ', 0, col++, attr);
}
room = scol - col + tabwidth - 1;
if (room > 0)
{
get_trans_bufname(cwp->w_buffer);
shorten_dir(NameBuff);
len = vim_strsize(NameBuff);
p = NameBuff;
#ifdef FEAT_MBYTE
if (has_mbyte)
while (len > room)
{
len -= ptr2cells(p);
MB_PTR_ADV(p);
}
else
#endif
if (len > room)
{
p += len - room;
len = room;
}
if (len > Columns - col - 1)
len = Columns - col - 1;
screen_puts_len(p, (int)STRLEN(p), 0, col, attr);
col += len;
}
screen_putchar(' ', 0, col++, attr);
++tabcount;
while (scol < col)
TabPageIdxs[scol++] = tabcount;
}
if (use_sep_chars)
c = '_';
else
c = ' ';
screen_fill(0, 1, col, (int)Columns, c, c, attr_fill);
if (first_tabpage->tp_next != NULL)
{
screen_putchar('X', 0, (int)Columns - 1, attr_nosel);
TabPageIdxs[Columns - 1] = -999;
}
}
redraw_tabline = FALSE;
}
void
get_trans_bufname(buf_T *buf)
{
if (buf_spname(buf) != NULL)
vim_strncpy(NameBuff, buf_spname(buf), MAXPATHL - 1);
else
home_replace(buf, buf->b_fname, NameBuff, MAXPATHL, TRUE);
trans_characters(NameBuff, MAXPATHL);
}
static int
fillchar_status(int *attr, win_T *wp)
{
int fill;
#ifdef FEAT_TERMINAL
if (bt_terminal(wp->w_buffer))
{
if (wp == curwin)
{
*attr = HL_ATTR(HLF_ST);
fill = fill_stl;
}
else
{
*attr = HL_ATTR(HLF_STNC);
fill = fill_stlnc;
}
}
else
#endif
if (wp == curwin)
{
*attr = HL_ATTR(HLF_S);
fill = fill_stl;
}
else
{
*attr = HL_ATTR(HLF_SNC);
fill = fill_stlnc;
}
if (*attr != 0 && ((HL_ATTR(HLF_S) != HL_ATTR(HLF_SNC)
|| wp != curwin || ONE_WINDOW)
|| (fill_stl != fill_stlnc)))
return fill;
if (wp == curwin)
return '^';
return '=';
}
static int
fillchar_vsep(int *attr)
{
*attr = HL_ATTR(HLF_C);
if (*attr == 0 && fill_vert == ' ')
return '|';
else
return fill_vert;
}
int
redrawing(void)
{
#ifdef FEAT_EVAL
if (disable_redraw_for_testing)
return 0;
else
#endif
return (!RedrawingDisabled
&& !(p_lz && char_avail() && !KeyTyped && !do_redraw));
}
int
messaging(void)
{
return (!(p_lz && char_avail() && !KeyTyped));
}
#ifdef FEAT_MENU
static void
redraw_win_toolbar(win_T *wp)
{
vimmenu_T *menu;
int item_idx = 0;
int item_count = 0;
int col = 0;
int next_col;
int off = (int)(current_ScreenLine - ScreenLines);
int fill_attr = syn_name2attr((char_u *)"ToolbarLine");
int button_attr = syn_name2attr((char_u *)"ToolbarButton");
vim_free(wp->w_winbar_items);
for (menu = wp->w_winbar->children; menu != NULL; menu = menu->next)
++item_count;
wp->w_winbar_items = (winbar_item_T *)alloc_clear(
(unsigned)sizeof(winbar_item_T) * (item_count + 1));
for (menu = wp->w_winbar->children;
menu != NULL && col < wp->w_width; menu = menu->next)
{
space_to_screenline(off + col, fill_attr);
if (++col >= wp->w_width)
break;
if (col > 1)
{
space_to_screenline(off + col, fill_attr);
if (++col >= wp->w_width)
break;
}
wp->w_winbar_items[item_idx].wb_startcol = col;
space_to_screenline(off + col, button_attr);
if (++col >= wp->w_width)
break;
next_col = text_to_screenline(wp, menu->name, col);
while (col < next_col)
{
ScreenAttrs[off + col] = button_attr;
++col;
}
wp->w_winbar_items[item_idx].wb_endcol = col;
wp->w_winbar_items[item_idx].wb_menu = menu;
++item_idx;
if (col >= wp->w_width)
break;
space_to_screenline(off + col, button_attr);
++col;
}
while (col < wp->w_width)
{
space_to_screenline(off + col, fill_attr);
++col;
}
wp->w_winbar_items[item_idx].wb_menu = NULL;
screen_line(wp->w_winrow, wp->w_wincol, (int)wp->w_width,
(int)wp->w_width, FALSE);
}
#endif
void
showruler(int always)
{
if (!always && !redrawing())
return;
#ifdef FEAT_INS_EXPAND
if (pum_visible())
{
curwin->w_redr_status = TRUE;
return;
}
#endif
#if defined(FEAT_STL_OPT)
if ((*p_stl != NUL || *curwin->w_p_stl != NUL) && curwin->w_status_height)
{
redraw_custom_statusline(curwin);
}
else
#endif
#ifdef FEAT_CMDL_INFO
win_redr_ruler(curwin, always);
#endif
#ifdef FEAT_TITLE
if (need_maketitle
# ifdef FEAT_STL_OPT
|| (p_icon && (stl_syntax & STL_IN_ICON))
|| (p_title && (stl_syntax & STL_IN_TITLE))
# endif
)
maketitle();
#endif
if (redraw_tabline)
draw_tabline();
}
#ifdef FEAT_CMDL_INFO
static void
win_redr_ruler(win_T *wp, int always)
{
#define RULER_BUF_LEN 70
char_u buffer[RULER_BUF_LEN];
int row;
int fillchar;
int attr;
int empty_line = FALSE;
colnr_T virtcol;
int i;
size_t len;
int o;
int this_ru_col;
int off = 0;
int width = Columns;
if (!p_ru)
return;
if (wp->w_cursor.lnum > wp->w_buffer->b_ml.ml_line_count)
return;
#ifdef FEAT_INS_EXPAND
if (wp == lastwin && lastwin->w_status_height == 0)
if (edit_submode != NULL)
return;
if (pum_visible())
return;
#endif
#ifdef FEAT_STL_OPT
if (*p_ruf)
{
int save_called_emsg = called_emsg;
called_emsg = FALSE;
win_redr_custom(wp, TRUE);
if (called_emsg)
set_string_option_direct((char_u *)"rulerformat", -1,
(char_u *)"", OPT_FREE, SID_ERROR);
called_emsg |= save_called_emsg;
return;
}
#endif
if (!(State & INSERT)
&& *ml_get_buf(wp->w_buffer, wp->w_cursor.lnum, FALSE) == NUL)
empty_line = TRUE;
validate_virtcol_win(wp);
if ( redraw_cmdline
|| always
|| wp->w_cursor.lnum != wp->w_ru_cursor.lnum
|| wp->w_cursor.col != wp->w_ru_cursor.col
|| wp->w_virtcol != wp->w_ru_virtcol
#ifdef FEAT_VIRTUALEDIT
|| wp->w_cursor.coladd != wp->w_ru_cursor.coladd
#endif
|| wp->w_topline != wp->w_ru_topline
|| wp->w_buffer->b_ml.ml_line_count != wp->w_ru_line_count
#ifdef FEAT_DIFF
|| wp->w_topfill != wp->w_ru_topfill
#endif
|| empty_line != wp->w_ru_empty)
{
cursor_off();
if (wp->w_status_height)
{
row = W_WINROW(wp) + wp->w_height;
fillchar = fillchar_status(&attr, wp);
off = wp->w_wincol;
width = wp->w_width;
}
else
{
row = Rows - 1;
fillchar = ' ';
attr = 0;
width = Columns;
off = 0;
}
virtcol = wp->w_virtcol;
if (wp->w_p_list && lcs_tab1 == NUL)
{
wp->w_p_list = FALSE;
getvvcol(wp, &wp->w_cursor, NULL, &virtcol, NULL);
wp->w_p_list = TRUE;
}
vim_snprintf((char *)buffer, RULER_BUF_LEN, "%ld,",
(wp->w_buffer->b_ml.ml_flags & ML_EMPTY)
? 0L
: (long)(wp->w_cursor.lnum));
len = STRLEN(buffer);
col_print(buffer + len, RULER_BUF_LEN - len,
empty_line ? 0 : (int)wp->w_cursor.col + 1,
(int)virtcol + 1);
i = (int)STRLEN(buffer);
get_rel_pos(wp, buffer + i + 1, RULER_BUF_LEN - i - 1);
o = i + vim_strsize(buffer + i + 1);
if (wp->w_status_height == 0)
++o;
this_ru_col = ru_col - (Columns - width);
if (this_ru_col < 0)
this_ru_col = 0;
if (this_ru_col < (width + 1) / 2)
this_ru_col = (width + 1) / 2;
if (this_ru_col + o < width)
{
while (this_ru_col + o < width && RULER_BUF_LEN > i + 4)
{
#ifdef FEAT_MBYTE
if (has_mbyte)
i += (*mb_char2bytes)(fillchar, buffer + i);
else
#endif
buffer[i++] = fillchar;
++o;
}
get_rel_pos(wp, buffer + i, RULER_BUF_LEN - i);
}
#ifdef FEAT_MBYTE
if (has_mbyte)
{
o = 0;
for (i = 0; buffer[i] != NUL; i += (*mb_ptr2len)(buffer + i))
{
o += (*mb_ptr2cells)(buffer + i);
if (this_ru_col + o > width)
{
buffer[i] = NUL;
break;
}
}
}
else
#endif
if (this_ru_col + (int)STRLEN(buffer) > width)
buffer[width - this_ru_col] = NUL;
screen_puts(buffer, row, this_ru_col + off, attr);
i = redraw_cmdline;
screen_fill(row, row + 1,
this_ru_col + off + (int)STRLEN(buffer),
(int)(off + width),
fillchar, fillchar, attr);
redraw_cmdline = i;
wp->w_ru_cursor = wp->w_cursor;
wp->w_ru_virtcol = wp->w_virtcol;
wp->w_ru_empty = empty_line;
wp->w_ru_topline = wp->w_topline;
wp->w_ru_line_count = wp->w_buffer->b_ml.ml_line_count;
#ifdef FEAT_DIFF
wp->w_ru_topfill = wp->w_topfill;
#endif
}
}
#endif
#if defined(FEAT_LINEBREAK) || defined(PROTO)
int
number_width(win_T *wp)
{
int n;
linenr_T lnum;
if (wp->w_p_rnu && !wp->w_p_nu)
lnum = wp->w_height;
else
lnum = wp->w_buffer->b_ml.ml_line_count;
if (lnum == wp->w_nrwidth_line_count && wp->w_nuw_cached == wp->w_p_nuw)
return wp->w_nrwidth_width;
wp->w_nrwidth_line_count = lnum;
n = 0;
do
{
lnum /= 10;
++n;
} while (lnum > 0);
if (n < wp->w_p_nuw - 1)
n = wp->w_p_nuw - 1;
wp->w_nrwidth_width = n;
wp->w_nuw_cached = wp->w_p_nuw;
return n;
}
#endif
int
screen_screencol(void)
{
return screen_cur_col;
}
int
screen_screenrow(void)
{
return screen_cur_row;
}