blob: bc8e4d2ad7b8d4f9e4482d5e46da633d2240c121 [file] [log] [blame]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001/* vi:set ts=8 sts=4 sw=4 noet:
2 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 * See README.txt for an overview of the Vim source code.
8 */
9
10/*
11 * drawline.c: Functions for drawing window lines on the screen.
Bram Moolenaare89aeed2022-08-22 13:00:16 +010012 * This is the middle level, drawscreen.c is the higher level and screen.c the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020013 * lower level.
14 */
15
16#include "vim.h"
17
18#ifdef FEAT_SYN_HL
19/*
20 * Advance **color_cols and return TRUE when there are columns to draw.
21 */
22 static int
23advance_color_col(int vcol, int **color_cols)
24{
25 while (**color_cols >= 0 && vcol > **color_cols)
26 ++*color_cols;
27 return (**color_cols >= 0);
28}
29#endif
30
31#ifdef FEAT_SYN_HL
32/*
33 * Used when 'cursorlineopt' contains "screenline": compute the margins between
34 * which the highlighting is used.
35 */
36 static void
37margin_columns_win(win_T *wp, int *left_col, int *right_col)
38{
39 // cache previous calculations depending on w_virtcol
40 static int saved_w_virtcol;
41 static win_T *prev_wp;
zeertzjq86dc4f82024-09-14 10:37:17 +020042 static int prev_width1;
43 static int prev_width2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020044 static int prev_left_col;
45 static int prev_right_col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020046
47 int cur_col_off = win_col_off(wp);
48 int width1;
49 int width2;
50
zeertzjq86dc4f82024-09-14 10:37:17 +020051 width1 = wp->w_width - cur_col_off;
52 width2 = width1 + win_col_off2(wp);
53
54 if (saved_w_virtcol == wp->w_virtcol && prev_wp == wp
55 && prev_width1 == width1 && prev_width2 == width2)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020056 {
57 *right_col = prev_right_col;
58 *left_col = prev_left_col;
59 return;
60 }
61
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020062 *left_col = 0;
63 *right_col = width1;
64
zeertzjq59149f02024-09-14 10:40:29 +020065 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020066 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
67 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
68 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
69
70 // cache values
71 prev_left_col = *left_col;
72 prev_right_col = *right_col;
73 prev_wp = wp;
zeertzjq86dc4f82024-09-14 10:37:17 +020074 prev_width1 = width1;
75 prev_width2 = width2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020076 saved_w_virtcol = wp->w_virtcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +020077}
78#endif
79
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000080#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
81 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
82// using an attribute for the whole line
83# define LINE_ATTR
84#endif
85
Bram Moolenaar1306b362022-08-06 15:59:06 +010086// structure with variables passed between win_line() and other functions
87typedef struct {
88 int draw_state; // what to draw next
89
90 linenr_T lnum; // line number to be drawn
91
92 int startrow; // first row in the window to be drawn
93 int row; // row in the window, excl w_winrow
94 int screen_row; // row on the screen, incl w_winrow
95
96 long vcol; // virtual column, before wrapping
97 int col; // visual column on screen, after wrapping
98#ifdef FEAT_CONCEAL
99 int boguscols; // nonexistent columns added to "col" to force
100 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000103 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100104#ifdef FEAT_SYN_HL
105 int draw_color_col; // highlight colorcolumn
106 int *color_cols; // pointer to according columns array
107#endif
108 int eol_hl_off; // 1 if highlighted char after EOL
109
110 unsigned off; // offset in ScreenLines/ScreenAttrs
111
112 int win_attr; // background for the whole window, except
113 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100114 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100115#ifdef FEAT_SYN_HL
116 int cul_attr; // set when 'cursorline' active
117#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000118#ifdef LINE_ATTR
119 int line_attr; // for the whole line, includes 'cursorline'
120#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100121
122 int screen_line_flags; // flags for screen_line()
123
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100124 int fromcol; // start of inverting
125 int tocol; // end of inverting
126
127#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100128 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100129 int need_showbreak; // overlong line, skipping first x chars
130 int dont_use_showbreak; // do not use 'showbreak'
131#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100132#ifdef FEAT_PROP_POPUP
133 int text_prop_above_count;
134#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100135
Bram Moolenaar1306b362022-08-06 15:59:06 +0100136 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
137 int cul_screenline;
138
139 int char_attr; // attributes for the next character
140
141 int n_extra; // number of extra bytes
142 char_u *p_extra; // string of extra chars, plus NUL, only used
143 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100144 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000145 int extra_attr; // attributes for p_extra, should be combined
146 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000147 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100148 int c_extra; // extra chars, all the same
149 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200150 int extra_for_textprop; // n_extra set for textprop
151 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100152
153 // saved "extra" items for when draw_state becomes WL_LINE (again)
154 int saved_n_extra;
155 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100156 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000158 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000159 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100160 int saved_c_extra;
161 int saved_c_final;
162 int saved_char_attr;
163
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100164 char_u extra[NUMBUFLEN + MB_MAXBYTES];
165 // "%ld " and 'fdc' must fit in here, as well
166 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100167
Bram Moolenaar1306b362022-08-06 15:59:06 +0100168#ifdef FEAT_DIFF
169 hlf_T diff_hlf; // type of diff highlighting
170#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100171 int filler_lines; // nr of filler lines to be drawn
172 int filler_todo; // nr of filler lines still to do + 1
173#ifdef FEAT_SIGNS
174 sign_attrs_T sattr;
175#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200176#ifdef FEAT_LINEBREAK
177 // do consider wrapping in linebreak mode only after encountering
178 // a non whitespace char
179 int need_lbr;
180#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100181} winlinevars_T;
182
183// draw_state values for items that are drawn in sequence:
184#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100185#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100186#ifdef FEAT_FOLDING
187# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
188#else
189# define WL_FOLD WL_CMDLINE
190#endif
191#ifdef FEAT_SIGNS
192# define WL_SIGN (WL_FOLD + 1) // column for signs
193#else
194# define WL_SIGN WL_FOLD // column for signs
195#endif
196#define WL_NR (WL_SIGN + 1) // line number
197#ifdef FEAT_LINEBREAK
198# define WL_BRI (WL_NR + 1) // 'breakindent'
199#else
200# define WL_BRI WL_NR
201#endif
202#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
203# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
204#else
205# define WL_SBR WL_BRI
206#endif
207#define WL_LINE (WL_SBR + 1) // text in the line
208
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100209#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200210/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000211 * Return TRUE if CursorLineSign highlight is to be used.
212 */
213 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100214use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000215{
216 return wp->w_p_cul
217 && lnum == wp->w_cursor.lnum
218 && (wp->w_p_culopt_flags & CULOPT_NBR);
219}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000221
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100222
223#ifdef FEAT_FOLDING
224/*
225 * Setup for drawing the 'foldcolumn', if there is one.
226 */
227 static void
228handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
229{
230 int fdc = compute_foldcolumn(wp, 0);
231
232 if (fdc <= 0)
233 return;
234
235 // Allocate a buffer, "wlv->extra[]" may already be in use.
236 vim_free(wlv->p_extra_free);
237 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000238 if (wlv->p_extra_free == NULL)
239 return;
240
241 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100242 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000243 wlv->p_extra_free[wlv->n_extra] = NUL;
244 wlv->p_extra = wlv->p_extra_free;
245 wlv->c_extra = NUL;
246 wlv->c_final = NUL;
247 if (use_cursor_line_highlight(wp, wlv->lnum))
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
249 else
250 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100251}
252#endif
253
254#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000255/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100256 * Get information needed to display the sign in line "wlv->lnum" in window
257 * "wp".
258 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200259 * Otherwise the sign is going to be displayed in the sign column.
260 */
261 static void
262get_sign_display_info(
263 int nrcol,
264 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100265 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200266{
267 int text_sign;
268# ifdef FEAT_SIGN_ICONS
269 int icon_sign;
270# endif
271
272 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100273 wlv->c_extra = ' ';
274 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100276 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200277 else
278 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100279 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000281 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100282 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100283 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200284 }
285
Bram Moolenaar1306b362022-08-06 15:59:06 +0100286 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100288 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200289#endif
290 )
291 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100294 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200295 if (gui.in_use && icon_sign != 0)
296 {
297 // Use the image in this position.
298 if (nrcol)
299 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100300 wlv->c_extra = NUL;
John Marriottf51ff962024-06-02 19:44:11 +0200301 wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
302 "%-*c ", number_width(wp), SIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100303 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200304 }
305 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100306 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200307# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100308 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
309 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200310 {
311 if (nrcol)
312 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100313 wlv->c_extra = NUL;
John Marriottf51ff962024-06-02 19:44:11 +0200314 wlv->n_extra = vim_snprintf((char *)wlv->extra, sizeof(wlv->extra),
315 "%-*c ", number_width(wp), MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100316 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200317 }
318 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100319 wlv->c_extra = MULTISIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200320 }
321# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100322 wlv->c_final = NUL;
323 wlv->char_attr = icon_sign;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200324 }
325 else
326# endif
327 if (text_sign != 0)
328 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100329 wlv->p_extra = wlv->sattr.sat_text;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100330 if (wlv->p_extra != NULL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200331 {
332 if (nrcol)
333 {
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100334 int width = number_width(wp) - 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200335
John Marriottf51ff962024-06-02 19:44:11 +0200336 vim_memset(wlv->extra, ' ', width);
337 wlv->n_extra = width;
338 wlv->n_extra += vim_snprintf((char *)wlv->extra + width,
339 sizeof(wlv->extra) - width, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100340 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200341 }
John Marriottf51ff962024-06-02 19:44:11 +0200342 else
343 wlv->n_extra = (int)STRLEN(wlv->p_extra);
344
Bram Moolenaar1306b362022-08-06 15:59:06 +0100345 wlv->c_extra = NUL;
346 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200347 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000348
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100349 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100350 && wlv->sattr.sat_culhl > 0)
351 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000352 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100353 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200354 }
355 }
356}
357#endif
358
Bram Moolenaard7657e92022-09-20 18:59:30 +0100359/*
360 * Display the absolute or relative line number. After the first row fill with
361 * blanks when the 'n' flag isn't in 'cpo'.
362 */
363 static void
364handle_lnum_col(
365 win_T *wp,
366 winlinevars_T *wlv,
367 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100368 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100369{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100370 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100371 int lnum_row = wlv->startrow + wlv->filler_lines
372#ifdef FEAT_PROP_POPUP
373 + wlv->text_prop_above_count
374#endif
375 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100376
Bram Moolenaard7657e92022-09-20 18:59:30 +0100377 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100378 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100379 // there is no line number in a wrapped line when "n" is in
380 // 'cpoptions', but 'breakindent' assumes it anyway.
381 && !((has_cpo_n
382#ifdef FEAT_LINEBREAK
383 && !wp->w_p_bri
384#endif
385 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100386 {
387#ifdef FEAT_SIGNS
388 // If 'signcolumn' is set to 'number' and a sign is present
389 // in 'lnum', then display the sign instead of the line
390 // number.
391 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
392 get_sign_display_info(TRUE, wp, wlv);
393 else
394#endif
395 {
396 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100397 // When there are text properties above the line put the line number
398 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100399 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100400 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100401 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100402 {
403 long num;
404 char *fmt = "%*ld ";
405
406 if (wp->w_p_nu && !wp->w_p_rnu)
407 // 'number' + 'norelativenumber'
408 num = (long)wlv->lnum;
409 else
410 {
411 // 'relativenumber', don't use negative numbers
412 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
413 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
414 {
415 // 'number' + 'relativenumber'
416 num = wlv->lnum;
417 fmt = "%-*ld ";
418 }
419 }
420
John Marriottf51ff962024-06-02 19:44:11 +0200421 vim_snprintf((char *)wlv->extra, sizeof(wlv->extra), fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100422 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100423 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
424 ++wlv->p_extra)
425 *wlv->p_extra = '-';
426#ifdef FEAT_RIGHTLEFT
427 if (wp->w_p_rl) // reverse line numbers
428 {
429 char_u *p1, *p2;
430 int t;
431
432 // like rl_mirror(), but keep the space at the end
433 p2 = skipwhite(wlv->extra);
434 p2 = skiptowhite(p2) - 1;
435 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
436 {
437 t = *p1;
438 *p1 = *p2;
439 *p2 = t;
440 }
441 }
442#endif
443 wlv->p_extra = wlv->extra;
444 wlv->c_extra = NUL;
445 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100446 }
447 else
448 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100449 wlv->c_extra = ' ';
450 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100451 }
452 wlv->n_extra = number_width(wp) + 1;
453 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
454#ifdef FEAT_SYN_HL
455 // When 'cursorline' is set highlight the line number of
456 // the current line differently.
457 // When 'cursorlineopt' does not have "line" only
458 // highlight the line number itself.
459 // TODO: Can we use CursorLine instead of CursorLineNr
460 // when CursorLineNr isn't set?
461 if (wp->w_p_cul
462 && wlv->lnum == wp->w_cursor.lnum
463 && (wp->w_p_culopt_flags & CULOPT_NBR)
464 && (wlv->row == wlv->startrow + wlv->filler_lines
465 || (wlv->row > wlv->startrow + wlv->filler_lines
466 && (wp->w_p_culopt_flags & CULOPT_LINE))))
467 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
468#endif
469 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
470 && HL_ATTR(HLF_LNA) != 0)
471 // Use LineNrAbove
472 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
473 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
474 && HL_ATTR(HLF_LNB) != 0)
475 // Use LineNrBelow
476 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
477 }
478#ifdef FEAT_SIGNS
479 if (num_attr)
480 wlv->char_attr = num_attr;
481#endif
482 }
483}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100484
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100485#ifdef FEAT_LINEBREAK
486 static void
487handle_breakindent(win_T *wp, winlinevars_T *wlv)
488{
489 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100490 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100491 // draw indent after showbreak value
492 wlv->draw_state = WL_BRI;
493 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
494 // After the showbreak, draw the breakindent
495 wlv->draw_state = WL_BRI - 1;
496
497 // draw 'breakindent': indent wrapped text accordingly
498 if (wlv->draw_state == WL_BRI - 1)
499 {
500 wlv->draw_state = WL_BRI;
501 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100502 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100503# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100504 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100505# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100506 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100507# ifdef FEAT_PROP_POPUP
508 && !wlv->dont_use_showbreak
509# endif
510 )
511 {
512 wlv->char_attr = 0;
513# ifdef FEAT_DIFF
514 if (wlv->diff_hlf != (hlf_T)0)
515 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
516# endif
517 wlv->p_extra = NULL;
518 wlv->c_extra = ' ';
519 wlv->c_final = NUL;
520 wlv->n_extra = get_breakindent_win(wp,
521 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
522 if (wlv->row == wlv->startrow)
523 {
524 wlv->n_extra -= win_col_off2(wp);
525 if (wlv->n_extra < 0)
526 wlv->n_extra = 0;
527 }
zeertzjq23627722023-12-27 19:08:53 +0100528
529 // Correct start of highlighted area for 'breakindent',
530 if (wlv->fromcol >= wlv->vcol
531 && wlv->fromcol < wlv->vcol + wlv->n_extra)
532 wlv->fromcol = wlv->vcol + wlv->n_extra;
533
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100534 // Correct end of highlighted area for 'breakindent',
535 // required when 'linebreak' is also set.
536 if (wlv->tocol == wlv->vcol)
537 wlv->tocol += wlv->n_extra;
538 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100539
540 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
541 && wp->w_briopt_sbr)
542 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100543 }
544}
545#endif
546
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100547#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
548 static void
549handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
550{
551# ifdef FEAT_DIFF
552 if (wlv->filler_todo > 0)
553 {
554 // Draw "deleted" diff line(s).
555 if (char2cells(wp->w_fill_chars.diff) > 1)
556 {
557 wlv->c_extra = '-';
558 wlv->c_final = NUL;
559 }
560 else
561 {
562 wlv->c_extra = wp->w_fill_chars.diff;
563 wlv->c_final = NUL;
564 }
565# ifdef FEAT_RIGHTLEFT
566 if (wp->w_p_rl)
567 wlv->n_extra = wlv->col + 1;
568 else
569# endif
570 wlv->n_extra = wp->w_width - wlv->col;
571 wlv->char_attr = HL_ATTR(HLF_DED);
572 }
573# endif
574
575# ifdef FEAT_LINEBREAK
576 char_u *sbr = get_showbreak_value(wp);
577 if (*sbr != NUL && wlv->need_showbreak)
578 {
579 // Draw 'showbreak' at the start of each broken line.
580 wlv->p_extra = sbr;
581 wlv->c_extra = NUL;
582 wlv->c_final = NUL;
583 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100584 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100585
586 // Correct start of highlighted area for 'showbreak'.
587 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
588 wlv->fromcol = wlv->vcol_sbr;
589
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100590 // Correct end of highlighted area for 'showbreak',
591 // required when 'linebreak' is also set.
592 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100593 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100594 // combine 'showbreak' with 'wincolor'
595 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
596# ifdef FEAT_SYN_HL
597 // combine 'showbreak' with 'cursorline'
598 if (wlv->cul_attr != 0)
599 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
600# endif
601 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100602
603 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
604 || !wp->w_briopt_sbr)
605 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100606# endif
607}
608#endif
609
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100610#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100611/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100612 * Return the cell size of virtual text after truncation.
613 */
614 static int
615textprop_size_after_trunc(
616 win_T *wp,
617 int flags, // TP_FLAG_ALIGN_*
618 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100619 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100620 char_u *text,
621 int *n_used_ptr)
622{
623 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100624 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100625 int strsize = 0;
John Marriottf51ff962024-06-02 19:44:11 +0200626 char_u *p;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100627
John Marriottf51ff962024-06-02 19:44:11 +0200628 // if the remaining size is too small and 'wrap' is set we wrap anyway and
Bram Moolenaar7e017462022-10-11 21:02:09 +0100629 // use the next line
630 if (space < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100631 space += wp->w_width;
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100632 if (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar13845c42022-10-09 15:26:03 +0100633 space -= padding;
John Marriottf51ff962024-06-02 19:44:11 +0200634
635 for (p = text; *p != NUL; p += (*mb_ptr2len)(p))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100636 {
John Marriottf51ff962024-06-02 19:44:11 +0200637 int clen = ptr2cells(p);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100638
639 if (strsize + clen > space)
640 break;
641 strsize += clen;
642 }
John Marriottf51ff962024-06-02 19:44:11 +0200643 *n_used_ptr = (int)(p - text);
644
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100645 return strsize;
646}
647
648/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100649 * Take care of padding, right-align and truncation of virtual text after a
650 * line.
651 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
652 * padding, right-align and truncation. Otherwise only the size is computed.
653 * When "n_attr" is NULL returns the number of screen cells used.
654 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100655 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100656 int
657text_prop_position(
658 win_T *wp,
659 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000660 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100661 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100662 int *n_extra, // nr of bytes for virtual text
663 char_u **p_extra, // virtual text
664 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000665 int *n_attr_skip, // cells to skip attr, NULL if not used
666 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200667{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100669 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000671 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100672 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000673 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100674 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100675 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100676 int before = room; // spaces before the text
677 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100678 int n_used = *n_extra;
679 char_u *l = NULL;
680 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100681 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100682 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200683
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100684 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100685 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100686 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100687
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100689 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100690 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100691 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100692 if (after < 0)
693 {
694 // text "above" has too much padding to fit
695 padding += after;
696 after = 0;
697 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100698 }
699 else
700 {
701 // Right-align: fill with before
702 if (right)
703 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000704
705 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000706 if (below && vcol == 0 && col_with_padding == col_off
707 && wp->w_width - col_off == before)
708 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000709
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100710 if (before < 0
711 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000712 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
713 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100714 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100715 if (right && (wrap
716 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 {
718 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100719 before = wp->w_width - col_off - strsize + room;
720 if (before < 0)
721 before = 0;
722 else
723 n_used = *n_extra;
724 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000725 else if (below && before > vcol && do_skip)
726 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100728 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100729 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100731
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100732 // With 'nowrap' add one to show the "extends" character if needed (it
733 // doesn't show if the text just fits).
734 if (!wp->w_p_wrap
735 && n_used < *n_extra
736 && wp->w_lcs_chars.ext != NUL
737 && wp->w_p_list)
738 ++n_used;
739
740 // add 1 for NUL, 2 for when '…' is used
741 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200742 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100743 if (n_attr == NULL || l != NULL)
744 {
745 int off = 0;
746
747 if (n_attr != NULL)
748 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100749 vim_memset(l, ' ', before);
750 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100751 if (padding > 0)
752 {
753 vim_memset(l + off, ' ', padding);
754 off += padding;
755 }
756 vim_strncpy(l + off, *p_extra, n_used);
757 off += n_used;
758 }
759 else
760 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100761 off = before + after + padding + n_used;
762 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100763 }
764 if (n_attr != NULL)
765 {
766 if (n_used < *n_extra && wp->w_p_wrap)
767 {
768 char_u *lp = l + off - 1;
769
770 if (has_mbyte)
771 {
h-east4c42c7e2023-04-17 21:44:57 +0100772 char_u buf[MB_MAXBYTES + 1];
773 char_u *cp = buf;
774
775 // change the last character to '…', converted to the
776 // current 'encoding'
777 STRCPY(buf, "…");
778 if (!enc_utf8)
779 {
780 vimconv_T vc;
781
782 vc.vc_type = CONV_NONE;
783 convert_setup(&vc, (char_u *)"utf-8", p_enc);
784 if (vc.vc_type != CONV_NONE)
785 {
786 cp = string_convert(&vc, buf, NULL);
787 if (cp == NULL)
788 {
789 // when conversion fails use '>'
790 cp = buf;
791 STRCPY(buf, ">");
792 }
793 convert_setup(&vc, NULL, NULL);
794 }
795 }
796
797 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100798 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100799 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100800 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100801 if (cp != buf)
802 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100803 }
804 else
805 // change last character to '>'
806 *lp = '>';
807 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100808 else if (after > 0)
809 {
810 vim_memset(l + off, ' ', after);
811 l[off + after] = NUL;
812 }
813
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100815 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100816 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000817 // n_attr_skip will not be decremented before draw_state is
818 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200819 *n_attr_skip = before + (padding > 0 ? padding : 0);
zeertzjq9352c282024-03-14 18:16:56 +0100820 *n_attr -= *n_attr_skip;
821 if (above)
822 *n_attr -= after;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100823 }
824 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100825 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100826
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100827 if (n_attr == NULL)
828 return cells;
829 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200830}
831#endif
832
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100833/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100834 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100835 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
836 * when 'showbreak' is not set.
zeertzjqd0c1b772024-03-16 15:03:33 +0100837 * When "clear_end" is TRUE clear until the end of the screen line.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100838 */
839 static void
zeertzjqd0c1b772024-03-16 15:03:33 +0100840wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100841{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100842 if (wlv->row == 0 && wp->w_skipcol > 0
843#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100844 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100845 && *get_showbreak_value(wp) == NUL
846#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100847 // do not overwrite the 'listchars' "precedes" text with "<<<"
848 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100849 {
850 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100851 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100852 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100853
Bram Moolenaareb4de622022-10-15 13:42:17 +0100854 if (wp->w_p_nu && wp->w_p_rnu)
855 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100856 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100857 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
858 {
859 ++off;
860 ++skip;
861 }
862
863 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100864 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100865 if ((*mb_off2cells)(off, max_off) > 1)
866 // When the first half of a double-width character is
867 // overwritten, change the second half to a space.
868 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100869 ScreenLines[off] = '<';
870 if (enc_utf8)
871 ScreenLinesUC[off] = 0;
872 ScreenAttrs[off] = HL_ATTR(HLF_AT);
873 ++off;
874 }
875 }
876
877 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
zeertzjqd0c1b772024-03-16 15:03:33 +0100878 clear_end ? wp->w_width : -wp->w_width,
879 wlv->vcol - 1, wlv->screen_line_flags);
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100880}
881
882/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100883 * Called when finished with the line: draw the screen line and handle any
884 * highlighting until the right of the window.
885 */
886 static void
887draw_screen_line(win_T *wp, winlinevars_T *wlv)
888{
889#ifdef FEAT_SYN_HL
890 long v;
zeertzjqf6272552024-03-17 10:01:47 +0100891 int wcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100892
893 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
894 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100895 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100896 else
897 v = wp->w_leftcol;
898
zeertzjqf6272552024-03-17 10:01:47 +0100899 wcol =
900# ifdef FEAT_RIGHTLEFT
901 wp->w_p_rl ? wp->w_width - wlv->col - 1 :
902# endif
903 wlv->col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100904 // check if line ends before left margin
zeertzjqf6272552024-03-17 10:01:47 +0100905 if (wlv->vcol < v + wcol - win_col_off(wp))
906 wlv->vcol = v + wcol - win_col_off(wp);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100907# ifdef FEAT_CONCEAL
908 // Get rid of the boguscols now, we want to draw until the right
909 // edge for 'cursorcolumn'.
910 wlv->col -= wlv->boguscols;
911 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000912# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100913# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000914# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100915# endif
916
917 if (wlv->draw_color_col)
918 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
919
920 if (((wp->w_p_cuc
921 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
922 && (int)wp->w_virtcol <
923 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
924 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000925 || wlv->draw_color_col
926# ifdef LINE_ATTR
927 || wlv->line_attr != 0
928# endif
zeertzjqf6272552024-03-17 10:01:47 +0100929 || wlv->win_attr != 0))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100930 {
931 int rightmost_vcol = 0;
932 int i;
933
934 if (wp->w_p_cuc)
935 rightmost_vcol = wp->w_virtcol;
936 if (wlv->draw_color_col)
937 // determine rightmost colorcolumn to possibly draw
938 for (i = 0; wlv->color_cols[i] >= 0; ++i)
939 if (rightmost_vcol < wlv->color_cols[i])
940 rightmost_vcol = wlv->color_cols[i];
941
zeertzjqf6272552024-03-17 10:01:47 +0100942 while (
943# ifdef FEAT_RIGHTLEFT
944 wp->w_p_rl ? (wlv->col >= 0) :
945# endif
946 (wlv->col < wp->w_width))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100947 {
948 ScreenLines[wlv->off] = ' ';
949 if (enc_utf8)
950 ScreenLinesUC[wlv->off] = 0;
zeertzjqf6272552024-03-17 10:01:47 +0100951
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100952 if (wlv->draw_color_col)
953 wlv->draw_color_col = advance_color_col(
954 VCOL_HLC, &wlv->color_cols);
955
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000956 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000957# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100958 if (wlv->line_attr != 0)
959 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000960# endif
zeertzjq9352c282024-03-14 18:16:56 +0100961 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
962 && wlv->lnum != wp->w_cursor.lnum)
963 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
964 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
965 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
zeertzjqf6272552024-03-17 10:01:47 +0100966 ScreenAttrs[wlv->off] = attr;
967 ScreenCols[wlv->off] = wlv->vcol;
968# ifdef FEAT_RIGHTLEFT
969 if (wp->w_p_rl)
970 {
971 --wlv->off;
972 --wlv->col;
973 }
974 else
975# endif
976 {
977 ++wlv->off;
978 ++wlv->col;
979 }
zeertzjqdeb22042024-03-17 19:44:30 +0100980 ++wlv->vcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100981
zeertzjqdeb22042024-03-17 19:44:30 +0100982 if (VCOL_HLC > rightmost_vcol
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000983# ifdef LINE_ATTR
984 && wlv->line_attr == 0
985# endif
986 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100987 break;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100988 }
989 }
990#endif
991
zeertzjqd0c1b772024-03-16 15:03:33 +0100992 // Set increasing virtual columns in ScreenCols[] to set correct curswant
993 // (or "coladd" for 'virtualedit') when clicking after end of line.
994 wlv->screen_line_flags |= SLF_INC_VCOL;
995 wlv_screen_line(wp, wlv, TRUE);
996 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100997 ++wlv->row;
998 ++wlv->screen_row;
999}
1000#undef VCOL_HLC
1001
1002/*
1003 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001004 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001005 */
1006 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +01001007win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001008{
1009 wlv->col = 0;
1010 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001011#ifdef FEAT_LINEBREAK
1012 wlv->need_lbr = FALSE;
1013#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001014
1015#ifdef FEAT_RIGHTLEFT
1016 if (wp->w_p_rl)
1017 {
1018 // Rightleft window: process the text in the normal direction, but put
1019 // it in current_ScreenLine[] from right to left. Start at the
1020 // rightmost column of the window.
1021 wlv->col = wp->w_width - 1;
1022 wlv->off += wlv->col;
1023 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1024 }
1025#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001026 if (save_extra)
1027 {
1028 // reset the drawing state for the start of a wrapped line
1029 wlv->draw_state = WL_START;
1030 wlv->saved_n_extra = wlv->n_extra;
1031 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001032 vim_free(wlv->saved_p_extra_free);
1033 wlv->saved_p_extra_free = wlv->p_extra_free;
1034 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001035 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001036 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001037 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001038 wlv->saved_c_extra = wlv->c_extra;
1039 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001040#ifdef FEAT_LINEBREAK
1041 wlv->need_lbr = TRUE;
1042#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001043#ifdef FEAT_SYN_HL
1044 if (!(wlv->cul_screenline
1045# ifdef FEAT_DIFF
1046 && wlv->diff_hlf == (hlf_T)0
1047# endif
1048 ))
1049 wlv->saved_char_attr = wlv->char_attr;
1050 else
1051#endif
1052 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001053
1054 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001055 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001056 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001057 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001058}
1059
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001060/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001061 * Called when wlv->draw_state is set to WL_LINE.
1062 */
1063 static void
1064win_line_continue(winlinevars_T *wlv)
1065{
1066 if (wlv->saved_n_extra > 0)
1067 {
1068 // Continue item from end of wrapped line.
1069 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001070 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001071 wlv->c_extra = wlv->saved_c_extra;
1072 wlv->c_final = wlv->saved_c_final;
1073 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001074 vim_free(wlv->p_extra_free);
1075 wlv->p_extra_free = wlv->saved_p_extra_free;
1076 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001077 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001078 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001079 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001080 wlv->char_attr = wlv->saved_char_attr;
1081 }
1082 else
1083 wlv->char_attr = wlv->win_attr;
1084}
1085
zeertzjqb7acea12022-12-12 13:20:43 +00001086#ifdef FEAT_SYN_HL
1087 static void
1088apply_cursorline_highlight(
1089 winlinevars_T *wlv,
1090 int sign_present UNUSED)
1091{
1092 wlv->cul_attr = HL_ATTR(HLF_CUL);
1093# ifdef FEAT_SIGNS
1094 // Combine the 'cursorline' and sign highlighting, depending on
1095 // the sign priority.
1096 if (sign_present && wlv->sattr.sat_linehl > 0)
1097 {
1098 if (wlv->sattr.sat_priority >= 100)
1099 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1100 else
1101 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1102 }
1103 else
1104# endif
1105# if defined(FEAT_QUICKFIX)
1106 // let the line attribute overrule 'cursorline', otherwise
1107 // it disappears when both have background set;
1108 // 'cursorline' can use underline or bold to make it show
1109 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1110# else
1111 wlv->line_attr = wlv->cul_attr;
1112# endif
1113}
1114#endif
1115
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001116/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001117 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001118 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001119 * When only updating the number column, "number_only" is set to the height of
1120 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001121 * "spv" is used to store information for spell checking, kept between
1122 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001123 * wp->w_virtcol needs to be valid.
1124 *
1125 * Return the number of last row the line occupies.
1126 */
1127 int
1128win_line(
1129 win_T *wp,
1130 linenr_T lnum,
1131 int startrow,
1132 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001133 int number_only,
1134 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001135{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001136 winlinevars_T wlv; // variables passed between functions
1137
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001139 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140 char_u *line; // current line
1141 char_u *ptr; // current position in "line"
glepnir6a38aff2024-12-16 21:56:16 +01001142 int in_curline = wp == curwin && lnum == curwin->w_cursor.lnum;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001143
Bram Moolenaar1306b362022-08-06 15:59:06 +01001144#ifdef FEAT_PROP_POPUP
1145 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1146#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001147#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001148 int in_linebreak = FALSE; // n_extra set for showing linebreak
1149#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001150 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001151 int lcs_prec_todo = wp->w_lcs_chars.prec;
1152 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001153
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001154 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001155 int saved_attr2 = 0; // char_attr saved for n_attr
1156 int n_attr3 = 0; // chars with overruling special attr
1157 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001158
zeertzjqb557f482023-08-22 22:07:34 +02001159 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1160 // w_skipcol or concealing
1161 int skipped_cells = 0; // nr of skipped cells for virtual text
1162 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001163 int fromcol_prev = -2; // start of inverting after cursor
1164 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001165 int lnum_in_visual_area = FALSE;
1166 pos_T pos;
1167 long v;
1168
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001169 int attr_pri = FALSE; // char_attr has priority
1170 int area_highlighting = FALSE; // Visual or incsearch highlighting
1171 // in this line
1172 int vi_attr = 0; // attributes for Visual and incsearch
1173 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001174 int area_attr = 0; // attributes desired by highlighting
zeertzjqf25d8f92024-12-18 21:12:25 +01001175 int search_attr = 0; // attributes desired by 'hlsearch' or
1176 // ComplMatchIns
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001177#ifdef FEAT_SYN_HL
1178 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1179 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001180 int prev_syntax_col = -1; // column of prev_syntax_attr
1181 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001182 int has_syntax = FALSE; // this buffer has syntax highl.
1183 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001184#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001185#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001186 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001187 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001188 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001189 int text_prop_next = 0; // next text property to use
1190 textprop_T *text_props = NULL;
1191 int *text_prop_idxs = NULL;
1192 int text_props_active = 0;
1193 proptype_T *text_prop_type = NULL;
1194 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001195 int text_prop_attr_comb = 0; // text_prop_attr combined with
1196 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001197 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001198 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001199 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001200 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001201 int saved_search_attr = 0; // search_attr to be used when n_extra
1202 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001203 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001204 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001205#endif
1206#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001207 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001208# define SPWORDLEN 150
1209 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1210 int nextlinecol = 0; // column where nextline[] starts
1211 int nextline_idx = 0; // index in nextline[] where next line
1212 // starts
1213 int spell_attr = 0; // attributes desired by spelling
1214 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001215 int cur_checked_col = 0; // checked column for current line
1216#endif
zeertzjqf25d8f92024-12-18 21:12:25 +01001217 int extra_check = FALSE; // has extra highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001218 int multi_attr = 0; // attributes desired by multibyte
1219 int mb_l = 1; // multi-byte byte length
1220 int mb_c = 0; // decoded multi-byte character
1221 int mb_utf8 = FALSE; // screen char is UTF-8 char
1222 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001223#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001224 int change_start = MAXCOL; // first col of changed area
1225 int change_end = -1; // last col of changed area
1226#endif
1227 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001228 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001229 int in_multispace = FALSE; // in multiple consecutive spaces
1230 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001231#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001232 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001233#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001234 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001235 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001236#ifdef FEAT_ARABIC
1237 int prev_c = 0; // previous Arabic character
1238 int prev_c1 = 0; // first composing char for prev_c
1239#endif
1240#if defined(LINE_ATTR)
1241 int did_line_attr = 0;
1242#endif
1243#ifdef FEAT_TERMINAL
1244 int get_term_attr = FALSE;
1245#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001246
Martin Tournoijba43e762022-10-13 22:12:15 +01001247#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001248 // margin columns for the screen line, needed for when 'cursorlineopt'
1249 // contains "screenline"
1250 int left_curline_col = 0;
1251 int right_curline_col = 0;
1252#endif
1253
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1255 int feedback_col = 0;
1256 int feedback_old_attr = -1;
1257#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001258
1259#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1260 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001261#endif
1262#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001263 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001264#endif
1265#ifdef FEAT_CONCEAL
1266 int syntax_flags = 0;
1267 int syntax_seqnr = 0;
1268 int prev_syntax_id = 0;
1269 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1270 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001271 int did_wcol = FALSE;
1272 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001273# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001274# define FIX_FOR_BOGUSCOLS \
1275 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001276 wlv.n_extra += wlv.vcol_off_co; \
1277 wlv.vcol -= wlv.vcol_off_co; \
1278 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001279 wlv.col -= wlv.boguscols; \
1280 old_boguscols = wlv.boguscols; \
1281 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001282 }
1283#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001284# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001285#endif
1286
1287 if (startrow > endrow) // past the end already!
1288 return startrow;
1289
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001290 CLEAR_FIELD(wlv);
1291
1292 wlv.lnum = lnum;
1293 wlv.startrow = startrow;
1294 wlv.row = startrow;
1295 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001296 wlv.fromcol = -10;
1297 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001298#ifdef FEAT_LINEBREAK
1299 wlv.vcol_sbr = -1;
1300#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001301
zeertzjqebfd8562024-02-06 10:59:03 +01001302 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001303 {
1304 // To speed up the loop below, set extra_check when there is linebreak,
1305 // trailing white space and/or syntax processing to be done.
1306#ifdef FEAT_LINEBREAK
1307 extra_check = wp->w_p_lbr;
1308#endif
1309#ifdef FEAT_SYN_HL
1310 if (syntax_present(wp) && !wp->w_s->b_syn_error
1311# ifdef SYN_TIME_LIMIT
1312 && !wp->w_s->b_syn_slow
1313# endif
1314 )
1315 {
1316 // Prepare for syntax highlighting in this line. When there is an
1317 // error, stop syntax highlighting.
1318 save_did_emsg = did_emsg;
1319 did_emsg = FALSE;
1320 syntax_start(wp, lnum);
1321 if (did_emsg)
1322 wp->w_s->b_syn_error = TRUE;
1323 else
1324 {
1325 did_emsg = save_did_emsg;
1326#ifdef SYN_TIME_LIMIT
1327 if (!wp->w_s->b_syn_slow)
1328#endif
1329 {
1330 has_syntax = TRUE;
1331 extra_check = TRUE;
1332 }
1333 }
1334 }
1335
1336 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001337 wlv.color_cols = wp->w_p_cc_cols;
1338 if (wlv.color_cols != NULL)
1339 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001340#endif
1341
1342#ifdef FEAT_TERMINAL
1343 if (term_show_buffer(wp->w_buffer))
1344 {
1345 extra_check = TRUE;
1346 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001347 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001348 }
1349#endif
1350
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001351 // handle Visual active in this window
1352 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1353 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001354 pos_T *top, *bot;
1355
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001356 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1357 {
1358 // Visual is after curwin->w_cursor
1359 top = &curwin->w_cursor;
1360 bot = &VIsual;
1361 }
1362 else
1363 {
1364 // Visual is before curwin->w_cursor
1365 top = &VIsual;
1366 bot = &curwin->w_cursor;
1367 }
1368 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1369 if (VIsual_mode == Ctrl_V)
1370 {
1371 // block mode
1372 if (lnum_in_visual_area)
1373 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001374 wlv.fromcol = wp->w_old_cursor_fcol;
1375 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001376 }
1377 }
1378 else
1379 {
1380 // non-block mode
1381 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001382 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 else if (lnum == top->lnum)
1384 {
1385 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001386 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001387 else
1388 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001389 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001390 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001391 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001392 }
1393 }
1394 if (VIsual_mode != 'V' && lnum == bot->lnum)
1395 {
1396 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1397 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001398 wlv.fromcol = -10;
1399 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001400 }
1401 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001402 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001403 else
1404 {
1405 pos = *bot;
1406 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001407 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1408 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001409 else
1410 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001411 getvvcol(wp, &pos, NULL, NULL,
1412 (colnr_T *)&wlv.tocol);
1413 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001414 }
1415 }
1416 }
1417 }
1418
1419 // Check if the character under the cursor should not be inverted
glepnir6a38aff2024-12-16 21:56:16 +01001420 if (!highlight_match && in_curline
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001421#ifdef FEAT_GUI
1422 && !gui.in_use
1423#endif
1424 )
1425 noinvcur = TRUE;
1426
1427 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001428 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001429 {
1430 area_highlighting = TRUE;
1431 vi_attr = HL_ATTR(HLF_V);
1432#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1433 if ((clip_star.available && !clip_star.owned
1434 && clip_isautosel_star())
1435 || (clip_plus.available && !clip_plus.owned
1436 && clip_isautosel_plus()))
1437 vi_attr = HL_ATTR(HLF_VNC);
1438#endif
1439 }
1440 }
1441
1442 // handle 'incsearch' and ":s///c" highlighting
1443 else if (highlight_match
1444 && wp == curwin
1445 && lnum >= curwin->w_cursor.lnum
1446 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1447 {
1448 if (lnum == curwin->w_cursor.lnum)
1449 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001450 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001451 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001452 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001453 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1454 {
1455 pos.lnum = lnum;
1456 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001457 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 }
1459 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001460 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001462 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1463 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001464 area_highlighting = TRUE;
1465 vi_attr = HL_ATTR(HLF_I);
1466 }
1467 }
1468
1469#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001470 wlv.filler_lines = diff_check(wp, lnum);
1471 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001472 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001473 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 {
1475 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001476 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001477 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001478 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001479 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001481 }
1482 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001483 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001484 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001485 area_highlighting = TRUE;
1486 }
1487 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001488 wlv.filler_lines = wp->w_topfill;
1489 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001490#endif
1491
1492#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001493 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001494 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001495 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001496#endif
1497
1498#ifdef LINE_ATTR
1499# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001500 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001501 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001502 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001503# endif
1504# if defined(FEAT_QUICKFIX)
1505 // Highlight the current line in the quickfix window.
1506 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001507 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001508# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001509 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510 area_highlighting = TRUE;
1511#endif
1512
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001513#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001514 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001516 // Prepare for spell checking.
1517 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001518
Luuk van Baal30805a12023-05-27 22:22:10 +01001519 // When a word wrapped from the previous line the start of the
1520 // current line is valid.
1521 if (lnum == spv->spv_checked_lnum)
1522 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001523 // Previous line was not spell checked, check for capital. This happens
1524 // for the first line in an updated region or after a closed fold.
1525 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1526 spv->spv_cap_col = 0;
1527 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001528 spv->spv_cap_col = -1;
1529 spv->spv_checked_lnum = 0;
1530
Luuk van Baal30805a12023-05-27 22:22:10 +01001531 // Get the start of the next line, so that words that wrap to the
1532 // next line are found too: "et<line-break>al.".
1533 // Trick: skip a few chars for C/shell/Vim comments
1534 nextline[SPWORDLEN] = NUL;
1535 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001536 {
1537 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1538 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1539 }
1540 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1541
1542 // If current line is empty, check first word in next line for capital.
1543 ptr = skipwhite(line);
1544 if (*ptr == NUL)
1545 {
1546 spv->spv_cap_col = 0;
1547 spv->spv_capcol_lnum = lnum + 1;
1548 }
1549 // For checking first word with a capital skip white space.
1550 else if (spv->spv_cap_col == 0)
1551 spv->spv_cap_col = ptr - line;
1552
Luuk van Baal30805a12023-05-27 22:22:10 +01001553 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001554 if (nextline[SPWORDLEN] == NUL)
1555 {
1556 // No next line or it is empty.
1557 nextlinecol = MAXCOL;
1558 nextline_idx = 0;
1559 }
1560 else
1561 {
zeertzjq94b7c322024-03-12 21:50:32 +01001562 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001563 if (v < SPWORDLEN)
1564 {
1565 // Short line, use it completely and append the start of the
1566 // next line.
1567 nextlinecol = 0;
1568 mch_memmove(nextline, line, (size_t)v);
1569 STRMOVE(nextline + v, nextline + SPWORDLEN);
1570 nextline_idx = v + 1;
1571 }
1572 else
1573 {
1574 // Long line, use only the last SPWORDLEN bytes.
1575 nextlinecol = v - SPWORDLEN;
1576 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1577 nextline_idx = SPWORDLEN + 1;
1578 }
1579 }
1580 }
1581#endif
1582
Luuk van Baale84c7732023-05-31 18:57:36 +01001583 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1584 ptr = line;
1585
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001586 if (wp->w_p_list)
1587 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001588 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001589 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001590 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001591 || wp->w_lcs_chars.trail
1592 || wp->w_lcs_chars.lead
1593 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001594 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001595
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001596 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001597 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001598 {
zeertzjq94b7c322024-03-12 21:50:32 +01001599 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1601 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001602 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001603 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001604 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001605 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001606 {
1607 leadcol = 0;
1608 while (VIM_ISWHITE(ptr[leadcol]))
1609 ++leadcol;
1610 if (ptr[leadcol] == NUL)
1611 // in a line full of spaces all of them are treated as trailing
1612 leadcol = (colnr_T)0;
1613 else
1614 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001615 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001616 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001617 }
1618
Bram Moolenaard7657e92022-09-20 18:59:30 +01001619 wlv.wcr_attr = get_wcr_attr(wp);
1620 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001621 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001622 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001623 area_highlighting = TRUE;
1624 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001625
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001626 // When w_skipcol is non-zero and there is virtual text above the actual
1627 // text, then this much of the virtual text is skipped.
1628 int skipcol_in_text_prop_above = 0;
1629
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001630#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001631 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001632 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001633
1634 char_u *prop_start;
1635 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1636 if (text_prop_count > 0)
1637 {
1638 // Make a copy of the properties, so that they are properly
1639 // aligned.
1640 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1641 if (text_props != NULL)
1642 mch_memmove(text_props, prop_start,
1643 text_prop_count * sizeof(textprop_T));
1644
1645 // Allocate an array for the indexes.
1646 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1647 if (text_prop_idxs == NULL)
1648 VIM_CLEAR(text_props);
1649
1650 if (text_props != NULL)
1651 {
1652 area_highlighting = TRUE;
1653 extra_check = TRUE;
1654
zeertzjq4e26a9a2023-12-03 17:50:47 +01001655 /* Find the last text property that inserts text. */
1656 for (int i = 0; i < text_prop_count; ++i)
1657 if (text_props[i].tp_id < 0)
1658 last_textprop_text_idx = i;
1659
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001660 // Text props "above" move the line number down to where the text
1661 // is. Only count the ones that are visible, not those that are
1662 // skipped because of w_skipcol.
1663 int text_width = wp->w_width - win_col_off(wp);
1664 for (int i = text_prop_count - 1; i >= 0; --i)
1665 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1666 {
1667 if (lnum == wp->w_topline
1668 && wp->w_skipcol - skipcol_in_text_prop_above
1669 >= text_width)
1670 {
1671 // This virtual text above is skipped, remove it from
1672 // the array.
1673 skipcol_in_text_prop_above += text_width;
1674 for (int j = i + 1; j < text_prop_count; ++j)
1675 text_props[j - 1] = text_props[j];
1676 ++i;
1677 --text_prop_count;
1678 }
1679 else
1680 ++wlv.text_prop_above_count;
1681 }
1682 }
1683 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001684
zeertzjqebfd8562024-02-06 10:59:03 +01001685 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001686 {
1687 // skip over rows only used for virtual text above
1688 wlv.row += wlv.text_prop_above_count;
zeertzjq918b92b2024-03-20 19:49:20 +01001689 if (wlv.row >= endrow)
1690 {
1691 vim_free(text_props);
1692 vim_free(text_prop_idxs);
Bram Moolenaara572b932023-02-19 14:34:37 +00001693 return wlv.row;
zeertzjq918b92b2024-03-20 19:49:20 +01001694 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001695 wlv.screen_row += wlv.text_prop_above_count;
1696 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001697#endif
1698
zeertzjqce53e3e2023-09-01 18:49:30 +02001699#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1700 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001701 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001702 {
1703 chartabsize_T cts;
1704 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1705 (void)win_lbr_chartabsize(&cts, NULL);
1706 vcol_first_char = cts.cts_first_char;
1707 clear_chartabsize_arg(&cts);
1708 }
1709#endif
1710
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1712 // first character to be displayed.
1713 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001714 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 else
1716 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001717 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001718 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001719 char_u *prev_ptr = ptr;
1720 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001721 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001722 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001723
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001724 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001725 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001726 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001727 {
zeertzjqb557f482023-08-22 22:07:34 +02001728 head = 0;
1729 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001730 cts.cts_vcol += charsize;
1731 prev_ptr = cts.cts_ptr;
1732 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001733 if (wp->w_p_list)
1734 {
1735 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1736 || (prev_ptr > line && prev_ptr[-1] == ' '));
1737 if (!in_multispace)
1738 multispace_pos = 0;
1739 else if (cts.cts_ptr >= line + leadcol
1740 && wp->w_lcs_chars.multispace != NULL)
1741 {
1742 ++multispace_pos;
1743 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1744 multispace_pos = 0;
1745 }
1746 else if (cts.cts_ptr < line + leadcol
1747 && wp->w_lcs_chars.leadmultispace != NULL)
1748 {
1749 ++multispace_pos;
1750 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1751 multispace_pos = 0;
1752 }
1753 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001754 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001755 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001756 ptr = cts.cts_ptr;
1757 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001758
1759 // When:
1760 // - 'cuc' is set, or
1761 // - 'colorcolumn' is set, or
1762 // - 'virtualedit' is set, or
1763 // - the visual mode is active,
1764 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001765 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001766#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001767 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001768#endif
1769 virtual_active() ||
1770 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001771 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772
1773 // Handle a character that's not completely on the screen: Put ptr at
1774 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001775 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001777 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001778 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001779 }
zeertzjqb557f482023-08-22 22:07:34 +02001780 if (v > wlv.vcol)
1781 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001782
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001783 // Adjust for when the inverted text is before the screen,
1784 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001785 if (wlv.tocol <= wlv.vcol)
1786 wlv.fromcol = 0;
1787 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1788 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001789
1790#ifdef FEAT_LINEBREAK
1791 // When w_skipcol is non-zero, first line needs 'showbreak'
1792 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001793 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001794#endif
1795#ifdef FEAT_SPELL
1796 // When spell checking a word we need to figure out the start of the
1797 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001798 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001799 {
1800 int len;
1801 colnr_T linecol = (colnr_T)(ptr - line);
1802 hlf_T spell_hlf = HLF_COUNT;
1803
1804 pos = wp->w_cursor;
1805 wp->w_cursor.lnum = lnum;
1806 wp->w_cursor.col = linecol;
Christ van Willegen - van Noort8e4c4c72024-05-17 18:49:27 +02001807 len = spell_move_to(wp, FORWARD, SMT_ALL, TRUE, &spell_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001808
1809 // spell_move_to() may call ml_get() and make "line" invalid
1810 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1811 ptr = line + linecol;
1812
John Marriottf51ff962024-06-02 19:44:11 +02001813 if (len == 0 || (int)wp->w_cursor.col > linecol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001814 {
1815 // no bad word found at line start, don't check until end of a
1816 // word
1817 spell_hlf = HLF_COUNT;
1818 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1819 }
1820 else
1821 {
1822 // bad word found, use attributes until end of word
1823 word_end = wp->w_cursor.col + len + 1;
1824
1825 // Turn index into actual attributes.
1826 if (spell_hlf != HLF_COUNT)
1827 spell_attr = highlight_attr[spell_hlf];
1828 }
1829 wp->w_cursor = pos;
1830
1831# ifdef FEAT_SYN_HL
1832 // Need to restart syntax highlighting for this line.
1833 if (has_syntax)
1834 syntax_start(wp, lnum);
1835# endif
1836 }
1837#endif
1838 }
1839
1840 // Correct highlighting for cursor that can't be disabled.
1841 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001842 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001843 {
1844 if (noinvcur)
1845 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001846 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 {
1848 // highlighting starts at cursor, let it start just after the
1849 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001850 fromcol_prev = wlv.fromcol;
1851 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001853 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001854 // restart highlighting after the cursor
1855 fromcol_prev = wp->w_virtcol;
1856 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001857 if (wlv.fromcol >= wlv.tocol)
1858 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001859 }
1860
1861#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001862 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001863 {
1864 v = (long)(ptr - line);
1865 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1866 &line, &screen_search_hl,
1867 &search_attr);
1868 ptr = line + v; // "line" may have been updated
1869 }
1870#endif
1871
zeertzjqf25d8f92024-12-18 21:12:25 +01001872 if ((State & MODE_INSERT) && in_curline && ins_compl_active())
1873 area_highlighting = TRUE;
1874
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875#ifdef FEAT_SYN_HL
1876 // Cursor line highlighting for 'cursorline' in the current window.
1877 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1878 {
1879 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001880 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 if (!(wp == curwin && VIsual_active)
1882 && wp->w_p_culopt_flags != CULOPT_NBR)
1883 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001884 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1886
zeertzjqb7acea12022-12-12 13:20:43 +00001887 // Only apply CursorLine highlight here when "screenline" is not
1888 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001889 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001890 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001891 else
1892 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001893 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001894 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1895 }
1896 area_highlighting = TRUE;
1897 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898 }
1899#endif
1900
Bram Moolenaar1306b362022-08-06 15:59:06 +01001901 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902
1903 // Repeat for the whole displayed line.
1904 for (;;)
1905 {
1906#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001907 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001908#endif
1909#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001910 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001911#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001912
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001913 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001914 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001915 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001916#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001918 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001919 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001920 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001921 }
1922#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001925 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001926 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001927 {
1928 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 wlv.n_extra = 1;
1930 wlv.c_extra = cmdwin_type;
1931 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001932 wlv.char_attr =
1933 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001934 }
1935 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001936#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001937 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001939 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001940 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001941 }
1942#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001944 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001945 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001946 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001947 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001948 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001949 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001950 }
1951#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001952 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001953 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001954 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001955 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001956 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001957 }
zeertzjqebfd8562024-02-06 10:59:03 +01001958
1959 // When only displaying the (relative) line number and that's done,
1960 // stop here.
1961 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1962 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001963 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001964 // Need to update more screen lines if:
1965 // - LineNrAbove or LineNrBelow is used, or
1966 // - still drawing filler lines.
1967 if ((wlv.row + 1 - wlv.startrow < number_only
1968 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1969#ifdef FEAT_DIFF
1970 || wlv.filler_todo > 0
1971#endif
1972 )
1973 {
1974 ++wlv.row;
1975 ++wlv.screen_row;
1976 if (wlv.row == endrow)
1977 break;
1978#ifdef FEAT_DIFF
1979 --wlv.filler_todo;
1980 if (wlv.filler_todo == 0 && wp->w_botfill)
1981 break;
1982#endif
1983 win_line_start(wp, &wlv, TRUE);
1984 continue;
1985 }
1986 else
1987 break;
1988 }
1989
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001991 // Check if 'breakindent' applies and show it.
1992 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1993 if (wlv.n_extra == 0)
1994 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001996#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001997 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001999 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002000 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 }
2002#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002003 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002005 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002006 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002007 }
2008 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002009
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002010#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002011 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002012 && wlv.vcol >= left_curline_col
2013 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002014 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015#endif
2016
2017 // When still displaying '$' of change command, stop at cursor.
zeertzjqf4ccada2024-12-17 20:50:19 +01002018 if (dollar_vcol >= 0 && in_curline && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002019 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002020 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021 // Pretend we have finished updating the window. Except when
2022 // 'cursorcolumn' is set.
2023#ifdef FEAT_SYN_HL
2024 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002025 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002026 else
2027#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002028 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 break;
2030 }
2031
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002033 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002034#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002035 if (text_props != NULL)
2036 {
2037 int pi;
2038 int bcol = (int)(ptr - line);
2039
Bram Moolenaar1306b362022-08-06 15:59:06 +01002040 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002041# ifdef FEAT_LINEBREAK
2042 && !in_linebreak
2043# endif
2044 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002045 --bcol; // still working on the previous char, e.g. Tab
2046
2047 // Check if any active property ends.
2048 for (pi = 0; pi < text_props_active; ++pi)
2049 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002050 int tpi = text_prop_idxs[pi];
2051 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002052
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002053 // An inline property ends when after the start column plus
2054 // length. An "above" property ends when used and n_extra
2055 // is zero.
2056 if ((tp->tp_col != MAXCOL
2057 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002058 {
2059 if (pi + 1 < text_props_active)
2060 mch_memmove(text_prop_idxs + pi,
2061 text_prop_idxs + pi + 1,
2062 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002063 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002064 --text_props_active;
2065 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002066# ifdef FEAT_LINEBREAK
2067 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002068 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002069 syntax_attr = 0;
2070# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002071 }
2072 }
2073
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002074# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002075 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002076 // not on the next char yet, don't start another prop
2077 --bcol;
2078# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002079 // Add any text property that starts in this column.
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002080 while (text_prop_next < text_prop_count)
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002081 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002082 int active;
2083 textprop_T *tp = &text_props[text_prop_next];
2084 if (tp->tp_col == MAXCOL)
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002085 {
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002086 if (bcol == 0 && (tp->tp_flags & TP_FLAG_ALIGN_ABOVE))
2087 active = TRUE;
2088 else if (*ptr != NUL)
2089 break;
2090 else
2091 {
2092 // With 'nowrap' and not in the first screen line only "below"
2093 // text prop can show.
2094 active = wp->w_p_wrap
2095 || wlv.row == startrow
2096 || (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
2097 }
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002098 }
Dylan Thacker-Smith1134fdd2024-03-28 11:49:46 +01002099 else
2100 {
2101 if (bcol < tp->tp_col - 1)
2102 break;
2103 active = bcol <= tp->tp_col - 1 + tp->tp_len;
2104 }
2105
2106 if (active)
2107 text_prop_idxs[text_props_active++] = text_prop_next;
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002108 ++text_prop_next;
2109 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002111 if (wlv.n_extra == 0 ||
2112 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002113 && !(text_prop_type != NULL &&
2114 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002115 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002116 {
2117 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002118 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002119 text_prop_flags = 0;
2120 text_prop_type = NULL;
2121 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002122 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002123 }
Dylan Thacker-Smithc8b47f22024-03-26 18:05:01 +01002124 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002125 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002126 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002127 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002128 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002129
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002130 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002131 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002132
2133 // Sort the properties on priority and/or starting last.
2134 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002135 sort_text_props(wp->w_buffer, text_props,
2136 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002137
2138 for (pi = 0; pi < text_props_active; ++pi)
2139 {
2140 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002141 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002143 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002144
Bram Moolenaarcd105412022-10-10 19:50:42 +01002145 // Only use a text property that can be displayed.
2146 // Skip "after" properties when wrap is off and at the
2147 // end of the window.
2148 if (pt != NULL
2149 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2150 && tp->tp_id != -MAXCOL
2151 && !(tp->tp_id < 0
2152 && !wp->w_p_wrap
2153 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2154 | TP_FLAG_ALIGN_ABOVE
2155 | TP_FLAG_ALIGN_BELOW)) == 0
2156 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002157 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002158 if (tp->tp_col == MAXCOL
2159 && *ptr == NUL
2160 && ((wp->w_p_list && lcs_eol_one > 0
2161 && (tp->tp_flags
2162 & TP_FLAG_ALIGN_ABOVE) == 0)
2163 || (ptr == line
2164 && !did_line
2165 && (tp->tp_flags
2166 & TP_FLAG_ALIGN_BELOW))))
2167 {
2168 // skip this prop, first display the '$' after
2169 // the line or display an empty line
2170 text_prop_follows = TRUE;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002171 continue;
2172 }
2173
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002174 if (pt->pt_hl_id > 0)
2175 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 text_prop_type = pt;
2177 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002178 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002179 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2180 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002181 text_prop_flags = pt->pt_flags;
2182 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002183 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002184 }
2185 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002186 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002187 && -text_prop_id
2188 <= wp->w_buffer->b_textprop_text.ga_len)
2189 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002190 textprop_T *tp = &text_props[used_tpi];
2191 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002192 ->b_textprop_text.ga_data)[
2193 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002194 int above = (tp->tp_flags
2195 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002196 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002197
2198 // reset the ID in the copy to avoid it being used
2199 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002200 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002201
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002202 if (p != NULL)
2203 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002204 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002205 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002206 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002207 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002208 int wrap = tp->tp_col < MAXCOL
2209 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002210 int padding = tp->tp_col == MAXCOL
2211 && tp->tp_len > 1
2212 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002213
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002214 // Insert virtual text before the current
2215 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002216 wlv.p_extra = p;
2217 wlv.c_extra = NUL;
2218 wlv.c_final = NUL;
2219 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002220 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002221 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002222 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2223 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002224 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002225 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002226 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002227 if (*ptr == NUL)
2228 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002229 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002230# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002231 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002232 {
2233 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002234 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002235 wlv.need_showbreak = FALSE;
2236 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002237 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002238# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002239 if ((right || above || below || !wrap
2240 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002241 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002242 char_u *prev_p_extra = wlv.p_extra;
2243 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002244
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002245 // Take care of padding, right-align and
2246 // truncation.
2247 // Shared with win_lbr_chartabsize(), must do
2248 // exactly the same.
2249 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002250 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002251# ifdef FEAT_RIGHTLEFT
2252 wp->w_p_rl
2253 ? wp->w_width - wlv.col - 1
2254 :
2255# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002256 wlv.col,
2257 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002258 &n_attr, &wlv.n_attr_skip,
2259 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002260 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002261 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002262 // wlv.p_extra was allocated
2263 vim_free(p_extra_free2);
2264 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002265 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002266
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002267 if (above)
zeertzjq91d26aa2024-10-27 19:23:34 +01002268 wlv.vcol_off_tp = vim_strsize(wlv.p_extra);
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002269
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002270 if (lcs_eol_one < 0
2271 && wp->w_p_wrap
2272 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002273 + wlv.n_extra - 2 > wp->w_width)
2274 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002275 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002276
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002277 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002278 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002279 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002280 {
2281 draw_screen_line(wp, &wlv);
2282
2283 // When line got too long for screen break
2284 // here.
2285 if (wlv.row == endrow)
2286 {
2287 ++wlv.row;
2288 break;
2289 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002290 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002291 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002292 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002293 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002294 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002295
Bram Moolenaarcd105412022-10-10 19:50:42 +01002296 // If the text didn't reach until the first window
2297 // column we need to skip cells.
2298 if (skip_cells > 0)
2299 {
2300 if (wlv.n_extra > skip_cells)
2301 {
2302 wlv.n_extra -= skip_cells;
2303 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002304 wlv.n_attr_skip -= skip_cells;
2305 if (wlv.n_attr_skip < 0)
2306 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002307 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002308 skip_cells = 0;
2309 }
2310 else
2311 {
2312 // the whole text is left of the window, drop
2313 // it and advance to the next one
2314 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002315 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002316 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002317 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002318 bail_out = TRUE;
2319 }
2320 }
2321
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002322 // If another text prop follows the condition below at
2323 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002324 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002325 // must wrap anyway.
2326 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002327 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002328 && (wp->w_p_wrap
2329 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002330 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002331
2332 if (bail_out)
2333 // starting a new line for "below"
2334 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002335 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002336 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002337 else if (text_prop_next < text_prop_count
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002338 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002339 || (!wp->w_p_wrap && wlv.col == wp->w_width - 1)))
2340 {
Bram Moolenaar398649e2022-08-04 15:03:48 +01002341 // When at last-but-one character and a text property
2342 // follows after it, we may need to flush the line after
2343 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002344 // Or when not wrapping and at the rightmost column.
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002345
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002346 int only_below_follows = !wp->w_p_wrap && wlv.col == wp->w_width - 1;
Dylan Thacker-Smithfe0a76b2024-03-28 11:47:32 +01002347 // TODO: Store "after"/"right"/"below" text properties in order
2348 // in the buffer so only `text_props[text_prop_count - 1]`
2349 // needs to be checked for following "below" virtual text
2350 for (int i = text_prop_next; i < text_prop_count; ++i)
2351 {
2352 if (text_props[i].tp_col == MAXCOL
2353 && (!only_below_follows
2354 || (text_props[i].tp_flags & TP_FLAG_ALIGN_BELOW)))
2355 {
2356 text_prop_follows = TRUE;
2357 break;
2358 }
2359 }
Dylan Thacker-Smithb6fac4d2024-03-28 11:40:41 +01002360 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002361 }
zeertzjq6e940d92023-08-17 23:21:40 +02002362
2363 if (wlv.start_extra_for_textprop)
2364 {
2365 wlv.start_extra_for_textprop = FALSE;
2366 // restore search_attr and area_attr when n_extra
2367 // is down to zero
2368 saved_search_attr = search_attr;
2369 saved_area_attr = area_attr;
2370 search_attr = 0;
2371 area_attr = 0;
2372 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002373#endif
2374
zeertzjq6e940d92023-08-17 23:21:40 +02002375 int *area_attr_p =
2376#ifdef FEAT_PROP_POPUP
2377 wlv.extra_for_textprop ? &saved_area_attr :
2378#endif
2379 &area_attr;
2380
2381 // handle Visual or match highlighting in this line
2382 if (wlv.vcol == wlv.fromcol
2383 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2384 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2385 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2386 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2387 || ((int)vcol_prev == fromcol_prev
2388 && vcol_prev < wlv.vcol // not at margin
2389 && wlv.vcol < wlv.tocol))
2390 *area_attr_p = vi_attr; // start highlighting
2391 else if (*area_attr_p != 0
2392 && (wlv.vcol == wlv.tocol
2393 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2394 *area_attr_p = 0; // stop highlighting
2395
Bram Moolenaare38fc862022-08-11 17:24:50 +01002396 if (wlv.n_extra == 0)
2397 {
zeertzjqf25d8f92024-12-18 21:12:25 +01002398#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002399 // Check for start/end of 'hlsearch' and other matches.
2400 // After end, check for start/end of next match.
2401 // When another match, have to check for start again.
2402 v = (long)(ptr - line);
2403 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2404 &screen_search_hl, &has_match_conc,
2405 &match_conc, did_line_attr, lcs_eol_one,
2406 &on_last_col);
2407 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002408
2409 // Do not allow a conceal over EOL otherwise EOL will be missed
2410 // and bad things happen.
2411 if (*ptr == NUL)
2412 has_match_conc = 0;
zeertzjqf25d8f92024-12-18 21:12:25 +01002413#else
2414 search_attr = 0;
zeertzjqe500ae82023-08-17 22:35:26 +02002415#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002416
zeertzjqf25d8f92024-12-18 21:12:25 +01002417 // Check if ComplMatchIns highlight is needed.
2418 if ((State & MODE_INSERT) && in_curline && ins_compl_active())
2419 {
2420 int ins_match_attr =
2421 ins_compl_col_range_attr((int)(ptr - line));
2422 if (ins_match_attr > 0)
2423 search_attr =
2424 hl_combine_attr(search_attr, ins_match_attr);
2425 }
2426 }
2427
Bram Moolenaare38fc862022-08-11 17:24:50 +01002428#ifdef FEAT_DIFF
2429 if (wlv.diff_hlf != (hlf_T)0)
2430 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002431 // When there is extra text (e.g. virtual text) it gets the
2432 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002433 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2434 && wlv.n_extra == 0)
2435 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002436 if (wlv.diff_hlf == HLF_TXD
2437 && ((ptr - line > change_end && wlv.n_extra == 0)
2438 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002439 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002440 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002441 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2442 && wp->w_p_culopt_flags != CULOPT_NBR
2443 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2444 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002445 wlv.line_attr = hl_combine_attr(
2446 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002447 }
2448#endif
2449
Bram Moolenaara74fda62019-10-19 17:38:03 +02002450#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002451 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002452 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002453 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002454# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002455 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002456 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002457# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002458 // Get syntax attribute.
2459 if (has_syntax)
2460 {
2461 // Get the syntax attribute for the character. If there
2462 // is an error, disable syntax highlighting.
2463 save_did_emsg = did_emsg;
2464 did_emsg = FALSE;
2465
2466 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002467 if (v == prev_syntax_col)
2468 // at same column again
2469 syntax_attr = prev_syntax_attr;
2470 else
2471 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002472# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002473 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002474# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002475 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002476# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002477 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002478# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002479 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002480 prev_syntax_col = v;
2481 prev_syntax_attr = syntax_attr;
2482 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002483
Bram Moolenaar34390282019-10-16 14:38:26 +02002484 if (did_emsg)
2485 {
2486 wp->w_s->b_syn_error = TRUE;
2487 has_syntax = FALSE;
2488 syntax_attr = 0;
2489 }
2490 else
2491 did_emsg = save_did_emsg;
2492# ifdef SYN_TIME_LIMIT
2493 if (wp->w_s->b_syn_slow)
2494 has_syntax = FALSE;
2495# endif
2496
2497 // Need to get the line again, a multi-line regexp may
2498 // have made it invalid.
2499 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2500 ptr = line + v;
2501# ifdef FEAT_CONCEAL
2502 // no concealing past the end of the line, it interferes
2503 // with line highlighting
2504 if (*ptr == NUL)
2505 syntax_flags = 0;
2506 else
2507 syntax_flags = get_syntax_info(&syntax_seqnr);
2508# endif
2509 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002510 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002511# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002512 // Combine text property highlight into syntax highlight.
2513 if (text_prop_type != NULL)
2514 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002515 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002516 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2517 else
2518 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002519 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002520 }
2521# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002522#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002523
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 // Decide which of the highlight attributes to use.
2525 attr_pri = TRUE;
2526#ifdef LINE_ATTR
2527 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002528 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002529 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002530 if (!highlight_match)
2531 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002532 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002533# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002534 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002535# endif
2536 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002538 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002539 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002540# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002542# endif
2543 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002544 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002545 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2546 || wlv.vcol < wlv.fromcol
2547 || vcol_prev < fromcol_prev
2548 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002549 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002550 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002552# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002553 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002554# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002555 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002556# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557 attr_pri = FALSE;
2558 }
2559#else
2560 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564#endif
2565 else
2566 {
2567 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002570#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002571 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002572#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002574#ifdef FEAT_PROP_POPUP
2575 // override with text property highlight when "override" is TRUE
2576 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002577 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002578#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002579 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002580
2581 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002582 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002583 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002584 if (wlv.char_attr == 0)
2585 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002586 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002587 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002588 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002589
2590 // Get the next character to put on the screen.
2591
2592 // The "p_extra" points to the extra stuff that is inserted to
2593 // represent special characters (non-printable stuff) and other
2594 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2597 // "p_extra[n_extra]".
2598 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002601 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002602 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002603 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2604 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2606 if (enc_utf8 && utf_char2len(c) > 1)
2607 {
2608 mb_utf8 = TRUE;
2609 u8cc[0] = 0;
2610 c = 0xc0;
2611 }
2612 else
2613 mb_utf8 = FALSE;
2614 }
2615 else
2616 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002617 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002618 if (has_mbyte)
2619 {
2620 mb_c = c;
2621 if (enc_utf8)
2622 {
2623 // If the UTF-8 character is more than one byte:
2624 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002625 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002626 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002627 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628 mb_l = 1;
2629 else if (mb_l > 1)
2630 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002631 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002632 mb_utf8 = TRUE;
2633 c = 0xc0;
2634 }
2635 }
2636 else
2637 {
2638 // if this is a DBCS character, put it in "mb_c"
2639 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 mb_l = 1;
2642 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002643 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002644 }
2645 if (mb_l == 0) // at the NUL at end-of-line
2646 mb_l = 1;
2647
2648 // If a double-width char doesn't fit display a '>' in the
2649 // last column.
2650 if ((
2651# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002652 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002653# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002654 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002655 && (*mb_char2cells)(mb_c) == 2)
2656 {
2657 c = '>';
2658 mb_c = c;
2659 mb_l = 1;
2660 mb_utf8 = FALSE;
2661 multi_attr = HL_ATTR(HLF_AT);
2662#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002663 if (wlv.cul_attr)
2664 multi_attr = hl_combine_attr(
2665 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002666#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002667 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002668
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 // put the pointer back to output the double-width
2670 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002671 ++wlv.n_extra;
2672 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 }
2674 else
2675 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002676 wlv.n_extra -= mb_l - 1;
2677 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678 }
2679 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002680 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002682 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002683#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002684 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002685 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002686 // Only restore search_attr and area_attr after "n_extra" in
2687 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002688 if (wlv.saved_n_extra <= 0)
2689 {
2690 if (search_attr == 0)
2691 search_attr = saved_search_attr;
2692 if (area_attr == 0 && *ptr != NUL)
2693 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002694
2695 if (wlv.extra_for_textprop)
2696 // wlv.extra_attr should be used at this position but
2697 // not any further.
2698 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002699 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002700
2701 wlv.extra_for_textprop = FALSE;
2702 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002703 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002704#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002705 }
2706 else
2707 {
2708#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002709 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002710#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002711 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002712
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002713 // Get a character from the line itself.
2714 c = *ptr;
2715#ifdef FEAT_LINEBREAK
2716 c0 = *ptr;
2717#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002718 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002719 {
2720#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002721 // text is finished, may display a "below" virtual text
2722 did_line = TRUE;
2723#endif
zeertzjqb557f482023-08-22 22:07:34 +02002724 // no more cells to skip
2725 skip_cells = 0;
2726 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002727
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002728 if (has_mbyte)
2729 {
2730 mb_c = c;
2731 if (enc_utf8)
2732 {
2733 // If the UTF-8 character is more than one byte: Decode it
2734 // into "mb_c".
2735 mb_l = utfc_ptr2len(ptr);
2736 mb_utf8 = FALSE;
2737 if (mb_l > 1)
2738 {
2739 mb_c = utfc_ptr2char(ptr, u8cc);
2740 // Overlong encoded ASCII or ASCII with composing char
2741 // is displayed normally, except a NUL.
2742 if (mb_c < 0x80)
2743 {
2744 c = mb_c;
2745#ifdef FEAT_LINEBREAK
2746 c0 = mb_c;
2747#endif
2748 }
2749 mb_utf8 = TRUE;
2750
2751 // At start of the line we can have a composing char.
2752 // Draw it as a space with a composing char.
2753 if (utf_iscomposing(mb_c))
2754 {
2755 int i;
2756
2757 for (i = Screen_mco - 1; i > 0; --i)
2758 u8cc[i] = u8cc[i - 1];
2759 u8cc[0] = mb_c;
2760 mb_c = ' ';
2761 }
2762 }
2763
2764 if ((mb_l == 1 && c >= 0x80)
2765 || (mb_l >= 1 && mb_c == 0)
2766 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2767 {
2768 // Illegal UTF-8 byte: display as <xx>.
2769 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002770 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002771# ifdef FEAT_RIGHTLEFT
2772 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002773 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002774# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002775 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002776 c = *wlv.p_extra;
2777 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002778 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002779 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2780 wlv.c_extra = NUL;
2781 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002782 if (area_attr == 0 && search_attr == 0)
2783 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002784 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002785 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002786 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002787 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002788 }
2789 }
2790 else if (mb_l == 0) // at the NUL at end-of-line
2791 mb_l = 1;
2792#ifdef FEAT_ARABIC
2793 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2794 {
2795 // Do Arabic shaping.
2796 int pc, pc1, nc;
2797 int pcc[MAX_MCO];
2798
2799 // The idea of what is the previous and next
2800 // character depends on 'rightleft'.
2801 if (wp->w_p_rl)
2802 {
2803 pc = prev_c;
2804 pc1 = prev_c1;
2805 nc = utf_ptr2char(ptr + mb_l);
2806 prev_c1 = u8cc[0];
2807 }
2808 else
2809 {
2810 pc = utfc_ptr2char(ptr + mb_l, pcc);
2811 nc = prev_c;
2812 pc1 = pcc[0];
2813 }
2814 prev_c = mb_c;
2815
2816 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2817 }
2818 else
2819 prev_c = mb_c;
2820#endif
2821 }
2822 else // enc_dbcs
2823 {
2824 mb_l = MB_BYTE2LEN(c);
2825 if (mb_l == 0) // at the NUL at end-of-line
2826 mb_l = 1;
2827 else if (mb_l > 1)
2828 {
2829 // We assume a second byte below 32 is illegal.
2830 // Hopefully this is OK for all double-byte encodings!
2831 if (ptr[1] >= 32)
2832 mb_c = (c << 8) + ptr[1];
2833 else
2834 {
2835 if (ptr[1] == NUL)
2836 {
2837 // head byte at end of line
2838 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002839 transchar_nonprint(wp->w_buffer, wlv.extra, c);
John Marriottf51ff962024-06-02 19:44:11 +02002840 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 }
2842 else
2843 {
2844 // illegal tail byte
2845 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002846 STRCPY(wlv.extra, "XX");
John Marriottf51ff962024-06-02 19:44:11 +02002847 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002848 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002849 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002850 wlv.c_extra = NUL;
2851 wlv.c_final = NUL;
2852 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002853 if (area_attr == 0 && search_attr == 0)
2854 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002855 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002856 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002857 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 // save current attr
2859 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002860 }
2861 mb_c = c;
2862 }
2863 }
2864 }
2865 // If a double-width char doesn't fit display a '>' in the
2866 // last column; the character is displayed at the start of the
2867 // next line.
2868 if ((
2869# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002871# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002872 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002873 && (*mb_char2cells)(mb_c) == 2)
2874 {
2875 c = '>';
2876 mb_c = c;
2877 mb_utf8 = FALSE;
2878 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002879 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 // Put pointer back so that the character will be
2881 // displayed at the start of the next line.
2882 --ptr;
2883#ifdef FEAT_CONCEAL
2884 did_decrement_ptr = TRUE;
2885#endif
2886 }
2887 else if (*ptr != NUL)
2888 ptr += mb_l - 1;
2889
2890 // If a double-width char doesn't fit at the left side display
2891 // a '<' in the first column. Don't do this for unprintable
2892 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002893 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002894 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002895 wlv.n_extra = 1;
2896 wlv.c_extra = MB_FILLER_CHAR;
2897 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 c = ' ';
2899 if (area_attr == 0 && search_attr == 0)
2900 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002901 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002902 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002903 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002904 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 }
2906 mb_c = c;
2907 mb_utf8 = FALSE;
2908 mb_l = 1;
2909 }
2910
2911 }
2912 ++ptr;
2913
2914 if (extra_check)
2915 {
2916#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002917 // Check spelling (unless at the end of the line).
2918 // Only do this when there is no syntax highlighting, the
2919 // @Spell cluster is not used or the current syntax item
2920 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002921 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002922 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002923 {
2924 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002925 // do not calculate cap_col at the end of the line or when
2926 // only white space is following
2927 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002928# ifdef FEAT_SYN_HL
2929 !has_syntax ||
2930# endif
2931 can_spell))
2932 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002933 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002934 int len;
2935 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002936
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002937 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002938 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939
2940 // Use nextline[] if possible, it has the start of the
2941 // next line concatenated.
2942 if ((prev_ptr - line) - nextlinecol >= 0)
2943 p = nextline + (prev_ptr - line) - nextlinecol;
2944 else
2945 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002946 spv->spv_cap_col -= (int)(prev_ptr - line);
2947 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2948 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002949 word_end = v + len;
2950
2951 // In Insert mode only highlight a word that
2952 // doesn't touch the cursor.
2953 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002954 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002955 && wp->w_cursor.lnum == lnum
2956 && wp->w_cursor.col >=
2957 (colnr_T)(prev_ptr - line)
2958 && wp->w_cursor.col < (colnr_T)word_end)
2959 {
2960 spell_hlf = HLF_COUNT;
2961 spell_redraw_lnum = lnum;
2962 }
2963
2964 if (spell_hlf == HLF_COUNT && p != prev_ptr
2965 && (p - nextline) + len > nextline_idx)
2966 {
2967 // Remember that the good word continues at the
2968 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002969 spv->spv_checked_lnum = lnum + 1;
2970 spv->spv_checked_col = (p - nextline) + len
2971 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002972 }
2973
2974 // Turn index into actual attributes.
2975 if (spell_hlf != HLF_COUNT)
2976 spell_attr = highlight_attr[spell_hlf];
2977
Luuk van Baal30805a12023-05-27 22:22:10 +01002978 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 {
2980 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002981 && (p - nextline) + spv->spv_cap_col
2982 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 {
2984 // Remember that the word in the next line
2985 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002986 spv->spv_capcol_lnum = lnum + 1;
2987 spv->spv_cap_col = ((p - nextline)
2988 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989 }
2990 else
2991 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002992 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993 }
2994 }
2995 }
2996 if (spell_attr != 0)
2997 {
2998 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3000 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003001 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003002 wlv.char_attr = hl_combine_attr(spell_attr,
3003 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003004 }
3005#endif
3006#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003007 // we don't want linebreak to apply for lines that start with
3008 // leading spaces, followed by long letters (since it would add
3009 // a break at the beginning of a line and this might be unexpected)
3010 //
3011 // So only allow to linebreak, once we have found chars not in
3012 // 'breakat' in the line.
3013 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
3014 !VIM_ISBREAK((int)*ptr))
3015 wlv.need_lbr = TRUE;
3016#endif
3017#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003018 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02003019 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
3021 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02003022 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
3023 : 0;
3024 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01003025 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003026
zeertzjqce53e3e2023-09-01 18:49:30 +02003027 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
3028# ifdef FEAT_PROP_POPUP
3029 - vcol_first_char,
3030# endif
3031 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003032# ifdef FEAT_PROP_POPUP
3033 // do not want virtual text counted here
3034 cts.cts_has_prop_with_text = FALSE;
3035# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003036 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003037 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003038
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003039 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003040 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003041 // line break, but for TABs the highlighting should
3042 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003043 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003044
Bram Moolenaar1306b362022-08-06 15:59:06 +01003045 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003046# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003047 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003048 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003049 wp->w_buffer->b_p_vts_array) - 1;
3050# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003051 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003052 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053# endif
3054
Bram Moolenaar1306b362022-08-06 15:59:06 +01003055 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3056 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003057# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003058 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003059 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003060# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003061 if (VIM_ISWHITE(c))
3062 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003063# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003064 if (c == TAB)
3065 // See "Tab alignment" below.
3066 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003067# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 if (!wp->w_p_list)
3069 c = ' ';
3070 }
3071 }
3072#endif
zeertzjqabc80812023-09-24 23:32:18 +02003073 if (wp->w_p_list)
3074 {
3075 in_multispace = c == ' ' && (*ptr == ' '
3076 || (prev_ptr > line && prev_ptr[-1] == ' '));
3077 if (!in_multispace)
3078 multispace_pos = 0;
3079 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003080
Bram Moolenaareed9d462021-02-15 20:38:25 +01003081 // 'list': Change char 160 to 'nbsp' and space to 'space'
3082 // setting in 'listchars'. But not when the character is
3083 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003084 if (wp->w_p_list
3085 && ((((c == 160 && mb_l == 1)
3086 || (mb_utf8
3087 && ((mb_c == 160 && mb_l == 2)
3088 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003089 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 || (c == ' '
3091 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003092 && (wp->w_lcs_chars.space
3093 || (in_multispace
3094 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003095 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003096 && ptr - line <= trailcol)))
3097 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003098 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3099 {
3100 c = wp->w_lcs_chars.multispace[multispace_pos++];
3101 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3102 multispace_pos = 0;
3103 }
3104 else
3105 c = (c == ' ') ? wp->w_lcs_chars.space
3106 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003107 if (area_attr == 0 && search_attr == 0)
3108 {
3109 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003110 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003111 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003112 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003113 }
3114 mb_c = c;
3115 if (enc_utf8 && utf_char2len(c) > 1)
3116 {
3117 mb_utf8 = TRUE;
3118 u8cc[0] = 0;
3119 c = 0xc0;
3120 }
3121 else
3122 mb_utf8 = FALSE;
3123 }
3124
zeertzjq2e7cba32022-06-10 15:30:32 +01003125 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3126 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003127 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003128 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3129 && wp->w_lcs_chars.leadmultispace != NULL)
3130 {
3131 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003132 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3133 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003134 multispace_pos = 0;
3135 }
3136
3137 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3138 c = wp->w_lcs_chars.trail;
3139
3140 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3141 c = wp->w_lcs_chars.lead;
3142
zeertzjq2e7cba32022-06-10 15:30:32 +01003143 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003144 c = wp->w_lcs_chars.space;
3145
3146
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003147 if (!attr_pri)
3148 {
3149 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003150 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003151 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003152 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003153 }
3154 mb_c = c;
3155 if (enc_utf8 && utf_char2len(c) > 1)
3156 {
3157 mb_utf8 = TRUE;
3158 u8cc[0] = 0;
3159 c = 0xc0;
3160 }
3161 else
3162 mb_utf8 = FALSE;
3163 }
3164 }
3165
3166 // Handling of non-printable characters.
3167 if (!vim_isprintc(c))
3168 {
3169 // when getting a character from the file, we may have to
3170 // turn it into something else on the way to putting it
3171 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003172 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003173 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003174 int tab_len = 0;
3175 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003176#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003177 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003178
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003179 // only adjust the tab_len, when at the first column
3180 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003181 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003182 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003183#endif
3184 // tab amount depends on current column
3185#ifdef FEAT_VARTABS
3186 tab_len = tabstop_padding(vcol_adjusted,
3187 wp->w_buffer->b_p_ts,
3188 wp->w_buffer->b_p_vts_array) - 1;
3189#else
3190 tab_len = (int)wp->w_buffer->b_p_ts
3191 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3192#endif
3193
3194#ifdef FEAT_LINEBREAK
3195 if (!wp->w_p_lbr || !wp->w_p_list)
3196#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003197 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003199 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003200 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003201#ifdef FEAT_LINEBREAK
3202 else
3203 {
3204 char_u *p;
3205 int len;
3206 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003207 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003208
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003209# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003210 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003211 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003212 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003213
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003214 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003215 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003216 && old_boguscols > 0
3217 && wlv.n_extra > tab_len)
3218 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003219# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003220 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003221 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003222 // If wlv.n_extra > 0, it gives the number of chars
3223 // to use for a tab, else we need to calculate the
3224 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003225 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3226 len = tab_len * tab2_len;
3227 if (wp->w_lcs_chars.tab3)
3228 len += mb_char2len(wp->w_lcs_chars.tab3)
3229 - tab2_len;
3230 if (wlv.n_extra > 0)
3231 len += wlv.n_extra - tab_len;
3232 c = wp->w_lcs_chars.tab1;
3233 p = alloc(len + 1);
3234 if (p == NULL)
3235 wlv.n_extra = 0;
3236 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003238 vim_memset(p, ' ', len);
3239 p[len] = NUL;
3240 vim_free(wlv.p_extra_free);
3241 wlv.p_extra_free = p;
3242 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003243 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003244 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003245
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003246 if (*p == NUL)
3247 {
3248 tab_len = i;
3249 break;
3250 }
3251
3252 // if tab3 is given, use it for the last
3253 // char
3254 if (wp->w_lcs_chars.tab3
3255 && i == tab_len - 1)
3256 lcs = wp->w_lcs_chars.tab3;
3257 p += mb_char2bytes(lcs, p);
3258 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003259 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003260 }
3261 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003262# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003263 // n_extra will be increased by
3264 // FIX_FOX_BOGUSCOLS macro below, so need to
3265 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003266 if (wlv.vcol_off_co > 0)
3267 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003268# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003269 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003271 }
3272#endif
3273#ifdef FEAT_CONCEAL
3274 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003275 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003276
3277 // Tab alignment should be identical regardless of
3278 // 'conceallevel' value. So tab compensates of all
3279 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003280 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003281 // line. Note that the tab can be longer than
3282 // 'tabstop' when there are concealed characters.
3283 FIX_FOR_BOGUSCOLS;
3284
3285 // Make sure, the highlighting for the tab char will be
3286 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003287 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003288 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003289 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 tab_len += vc_saved;
3291 }
3292#endif
3293 mb_utf8 = FALSE; // don't draw as UTF-8
3294 if (wp->w_p_list)
3295 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003296 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003297 ? wp->w_lcs_chars.tab3
3298 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003299#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003300 if (wp->w_p_lbr && wlv.p_extra != NULL
3301 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003302 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 else
3304#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003305 wlv.c_extra = wp->w_lcs_chars.tab2;
3306 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003308 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003309 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311 mb_c = c;
3312 if (enc_utf8 && utf_char2len(c) > 1)
3313 {
3314 mb_utf8 = TRUE;
3315 u8cc[0] = 0;
3316 c = 0xc0;
3317 }
3318 }
3319 else
3320 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003321 wlv.c_final = NUL;
3322 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323 c = ' ';
3324 }
3325 }
3326 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003327 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003329 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3330 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 && VIsual_mode != Ctrl_V
3332 && (
3333# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003334 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003335# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003336 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 && !(noinvcur
3338 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003339 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003340 && lcs_eol_one > 0)
3341 {
3342 // Display a '$' after the line or highlight an extra
3343 // character if the line break is included.
3344#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3345 // For a diff line the highlighting continues after the
3346 // "$".
3347 if (
3348# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003349 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003350# ifdef LINE_ATTR
3351 &&
3352# endif
3353# endif
3354# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003355 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356# endif
3357 )
3358#endif
3359 {
3360 // In virtualedit, visual selections may extend
3361 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003362 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003363 && wlv.tocol != MAXCOL
3364 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003365 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003366 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003367 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003368 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3369 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003370 else
3371 c = ' ';
3372 lcs_eol_one = -1;
3373 --ptr; // put it back at the NUL
3374 if (!attr_pri)
3375 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003376 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003377 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003378 n_attr = 1;
3379 }
3380 mb_c = c;
3381 if (enc_utf8 && utf_char2len(c) > 1)
3382 {
3383 mb_utf8 = TRUE;
3384 u8cc[0] = 0;
3385 c = 0xc0;
3386 }
3387 else
3388 mb_utf8 = FALSE; // don't draw as UTF-8
3389 }
3390 else if (c != NUL)
3391 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3393 if (wlv.n_extra == 0)
3394 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395#ifdef FEAT_RIGHTLEFT
3396 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003397 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003398#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003399 wlv.c_extra = NUL;
3400 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003401#ifdef FEAT_LINEBREAK
3402 if (wp->w_p_lbr)
3403 {
3404 char_u *p;
3405
Bram Moolenaar1306b362022-08-06 15:59:06 +01003406 c = *wlv.p_extra;
3407 p = alloc(wlv.n_extra + 1);
John Marriottf51ff962024-06-02 19:44:11 +02003408 if (p == NULL)
3409 wlv.n_extra = 0;
3410 else
3411 {
3412 vim_memset(p, ' ', wlv.n_extra);
3413 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3414 p[wlv.n_extra] = NUL;
3415 vim_free(wlv.p_extra_free);
3416 wlv.p_extra_free = wlv.p_extra = p;
3417 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418 }
3419 else
3420#endif
3421 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003422 wlv.n_extra = byte2cells(c) - 1;
3423 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424 }
3425 if (!attr_pri)
3426 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003427 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003428 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003429 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003430#ifdef FEAT_PROP_POPUP
3431 if (text_prop_type != NULL &&
3432 text_prop_flags & PT_FLAG_OVERRIDE)
3433 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3434#endif
3435
Bram Moolenaar1306b362022-08-06 15:59:06 +01003436 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003437 }
3438 mb_utf8 = FALSE; // don't draw as UTF-8
3439 }
3440 else if (VIsual_active
3441 && (VIsual_mode == Ctrl_V
3442 || VIsual_mode == 'v')
3443 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003444 && wlv.tocol != MAXCOL
3445 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003446 && (
3447#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003448 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003449#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003450 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003451 {
3452 c = ' ';
3453 --ptr; // put it back at the NUL
3454 }
3455#if defined(LINE_ATTR)
3456 else if ((
3457# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459# endif
3460# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003461 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003462# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003463 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 ) && (
3465# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003467# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471# endif
3472 < wp->w_width)))
3473 {
3474 // Highlight until the right side of the window
3475 c = ' ';
3476 --ptr; // put it back at the NUL
3477
3478 // Remember we do the char for line highlighting.
3479 ++did_line_attr;
3480
3481 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003482 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003484 || (wp->w_p_list &&
3485 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003486 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003487#ifdef FEAT_SIGNS
3488 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003489 // but not when cursorline is active
3490 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3491 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003492 wlv.char_attr = wlv.sattr.sat_linehl;
3493#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003494# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003495 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 wlv.diff_hlf = HLF_CHD;
3498 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003500 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003501 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3502 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003503 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003504 || (wlv.vcol >= left_curline_col
3505 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003506 wlv.char_attr = hl_combine_attr(
3507 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003508 }
3509 }
3510# endif
3511# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003512 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003513 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003514 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003515 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3516 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003517 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003518 if (!wlv.cul_screenline
3519 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003520 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003521 wlv.char_attr = hl_combine_attr(
3522 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003523 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003524 else if (wlv.line_attr)
3525 wlv.char_attr = hl_combine_attr(
3526 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003527 }
3528# endif
3529 }
3530#endif
3531 }
3532
3533#ifdef FEAT_CONCEAL
3534 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003535 && (wp != curwin || lnum != wp->w_cursor.lnum
3536 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003537 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3538 && !(lnum_in_visual_area
3539 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3540 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003541 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003542 if (((prev_syntax_id != syntax_seqnr
3543 && (syntax_flags & HL_CONCEAL) != 0)
3544 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003545 && (syn_get_sub_char() != NUL
3546 || (has_match_conc && match_conc)
3547 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003548 && wp->w_p_cole != 3)
3549 {
3550 // First time at this concealed item: display one
3551 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003552 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 c = match_conc;
3554 else if (syn_get_sub_char() != NUL)
3555 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003556 else if (wp->w_lcs_chars.conceal != NUL)
3557 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 else
3559 c = ' ';
3560
zeertzjq010e1532024-03-14 18:22:17 +01003561 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3562 // When the first char to be concealed is double-width,
3563 // need to advance one more virtual column.
3564 wlv.n_extra++;
3565
3566 mb_c = c;
3567 if (enc_utf8 && utf_char2len(c) > 1)
3568 {
3569 mb_utf8 = TRUE;
3570 u8cc[0] = 0;
3571 c = 0xc0;
3572 }
3573 else
3574 mb_utf8 = FALSE; // don't draw as UTF-8
3575
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003576 prev_syntax_id = syntax_seqnr;
3577
Bram Moolenaar1306b362022-08-06 15:59:06 +01003578 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003579 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003580 wlv.vcol += wlv.n_extra;
3581 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 {
3583# ifdef FEAT_RIGHTLEFT
3584 if (wp->w_p_rl)
3585 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003586 wlv.col -= wlv.n_extra;
3587 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003588 }
3589 else
3590# endif
3591 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003592 wlv.boguscols += wlv.n_extra;
3593 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 }
3595 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003596 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003597 n_attr = 0;
3598 }
zeertzjqb557f482023-08-22 22:07:34 +02003599 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 {
3601 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003602 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003603 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003604 }
3605 else
3606 {
3607 prev_syntax_id = 0;
3608 is_concealing = FALSE;
3609 }
3610
zeertzjqb557f482023-08-22 22:07:34 +02003611 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 // not showing the '>', put pointer back to avoid getting stuck
3613 ++ptr;
3614
3615#endif // FEAT_CONCEAL
3616 }
3617
3618#ifdef FEAT_CONCEAL
3619 // In the cursor line and we may be concealing characters: correct
3620 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003621 // With 'virtualedit' we may never reach cursor position, but we still
3622 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003623 if (!did_wcol && wlv.draw_state == WL_LINE
zeertzjqf4ccada2024-12-17 20:50:19 +01003624 && in_curline && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003625 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003627# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003629 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003630 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003631# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003632 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003633 if (wlv.vcol + skip_cells < wp->w_virtcol)
3634 // Cursor beyond end of the line with 'virtualedit'.
3635 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003636 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003637 did_wcol = TRUE;
3638 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003639# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003640 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003641# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 }
3643#endif
3644
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003645 // Use "wlv.extra_attr", but don't override visual selection
3646 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003647 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3648 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003649 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003650 && (!attr_pri
3651#ifdef FEAT_PROP_POPUP
3652 || (text_prop_flags & PT_FLAG_OVERRIDE)
3653#endif
3654 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003655 {
3656#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003657 if (wlv.line_attr)
3658 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003659 else
3660#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003661 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003662#ifdef FEAT_PROP_POPUP
3663 if (reset_extra_attr)
3664 {
3665 reset_extra_attr = FALSE;
3666 wlv.extra_attr = 0;
3667 }
3668#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003669 }
3670
3671#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3672 // XIM don't send preedit_start and preedit_end, but they send
3673 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3674 // im_is_preediting() here.
3675 if (p_imst == IM_ON_THE_SPOT
3676 && xic != NULL
3677 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003678 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 && !p_imdisable
3680 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003681 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 {
3683 colnr_T tcol;
3684
3685 if (preedit_end_col == MAXCOL)
3686 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3687 else
3688 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003689 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 {
3691 if (feedback_old_attr < 0)
3692 {
3693 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003694 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003695 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003696 wlv.char_attr = im_get_feedback_attr(feedback_col);
3697 if (wlv.char_attr < 0)
3698 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003699 feedback_col++;
3700 }
3701 else if (feedback_old_attr >= 0)
3702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003703 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003704 feedback_old_attr = -1;
3705 feedback_col = 0;
3706 }
3707 }
3708#endif
3709 // Handle the case where we are in column 0 but not on the first
3710 // character of the line and the user wants us to show us a
3711 // special character (via 'listchars' option "precedes:<char>".
3712 if (lcs_prec_todo != NUL
3713 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003714 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3715 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003716#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003717 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003718#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003719 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003720 && c != NUL)
3721 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003722 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003723 lcs_prec_todo = NUL;
3724 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3725 {
3726 // Double-width character being overwritten by the "precedes"
3727 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003728 wlv.c_extra = MB_FILLER_CHAR;
3729 wlv.c_final = NUL;
3730 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003731 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003732 wlv.extra_attr =
3733 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 }
3735 mb_c = c;
3736 if (enc_utf8 && utf_char2len(c) > 1)
3737 {
3738 mb_utf8 = TRUE;
3739 u8cc[0] = 0;
3740 c = 0xc0;
3741 }
3742 else
3743 mb_utf8 = FALSE; // don't draw as UTF-8
3744 if (!attr_pri)
3745 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 saved_attr3 = wlv.char_attr; // save current attr
3747 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003748 n_attr3 = 1;
3749 }
3750 }
3751
3752 // At end of the text line or just after the last character.
3753 if ((c == NUL
3754#if defined(LINE_ATTR)
3755 || did_line_attr == 1
3756#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003757 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003758 {
3759#ifdef FEAT_SEARCH_EXTRA
3760 // flag to indicate whether prevcol equals startcol of search_hl or
3761 // one of the matches
3762 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3763 (long)(ptr - line) - (c == NUL));
3764#endif
3765 // Invert at least one char, used for Visual and empty line or
3766 // highlight match at end of line. If it's beyond the last
3767 // char on the screen, just overwrite that one (tricky!) Not
3768 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003769 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003770 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 && (VIsual_mode != Ctrl_V
3772 || lnum == VIsual.lnum
3773 || lnum == curwin->w_cursor.lnum)
3774 && c == NUL)
3775#ifdef FEAT_SEARCH_EXTRA
3776 // highlight 'hlsearch' match at end of line
3777 || (prevcol_hl_flag
3778# ifdef FEAT_SYN_HL
3779 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3780 && !(wp == curwin && VIsual_active))
3781# endif
3782# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003783 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784# endif
3785# if defined(LINE_ATTR)
3786 && did_line_attr <= 1
3787# endif
3788 )
3789#endif
3790 ))
3791 {
3792 int n = 0;
3793
3794#ifdef FEAT_RIGHTLEFT
3795 if (wp->w_p_rl)
3796 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003798 n = 1;
3799 }
3800 else
3801#endif
3802 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 n = -1;
3805 }
3806 if (n != 0)
3807 {
3808 // At the window boundary, highlight the last character
3809 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003810 wlv.off += n;
3811 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812 }
3813 else
3814 {
3815 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003816 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003817 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003818 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003819 }
3820#ifdef FEAT_SEARCH_EXTRA
3821 if (area_attr == 0)
3822 {
3823 // Use attributes from match with highest priority among
3824 // 'search_hl' and the match list.
3825 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003826 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003827 }
3828#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003829 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003830 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003831#ifdef FEAT_RIGHTLEFT
3832 if (wp->w_p_rl)
3833 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003834 --wlv.col;
3835 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003836 }
3837 else
3838#endif
3839 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003840 ++wlv.col;
3841 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003842 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003843 ++wlv.vcol;
3844 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 }
3846 }
3847
3848 // At end of the text line.
3849 if (c == NUL)
3850 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003851#ifdef FEAT_PROP_POPUP
3852 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003854 // Put the pointer back to the NUL.
3855 --ptr;
3856 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003858 else
3859#endif
3860 {
3861 draw_screen_line(wp, &wlv);
3862
3863 // Update w_cline_height and w_cline_folded if the cursor line
3864 // was updated (saves a call to plines() later).
zeertzjqf4ccada2024-12-17 20:50:19 +01003865 if (in_curline)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003866 {
3867 curwin->w_cline_row = startrow;
3868 curwin->w_cline_height = wlv.row - startrow;
3869#ifdef FEAT_FOLDING
3870 curwin->w_cline_folded = FALSE;
3871#endif
3872 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3873 }
3874 break;
3875 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003876 }
3877
3878 // Show "extends" character from 'listchars' if beyond the line end and
3879 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003880 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003881 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 && wp->w_p_list
3883 && !wp->w_p_wrap
3884#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003885 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003886#endif
3887 && (
3888#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003889 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003890#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003891 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003892 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003893 || lcs_eol_one > 0
3894 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003895 || *wlv.p_extra != NUL))
3896#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003897 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003898#endif
3899 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003901 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003902 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003903 mb_c = c;
3904 if (enc_utf8 && utf_char2len(c) > 1)
3905 {
3906 mb_utf8 = TRUE;
3907 u8cc[0] = 0;
3908 c = 0xc0;
3909 }
3910 else
3911 mb_utf8 = FALSE;
3912 }
3913
3914#ifdef FEAT_SYN_HL
3915 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003916 if (wlv.draw_color_col)
3917 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918
3919 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3920 // highlight the cursor position itself.
3921 // Also highlight the 'colorcolumn' if it is different than
3922 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003923 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3924 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003926 if (((wlv.draw_state == WL_LINE
3927 || wlv.draw_state == WL_BRI
3928 || wlv.draw_state == WL_SBR)
3929 && !lnum_in_visual_area
3930 && search_attr == 0
3931 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003932# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003933 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003934# endif
3935 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003936 {
3937 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3938 && lnum != wp->w_cursor.lnum)
3939 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003940 vcol_save_attr = wlv.char_attr;
3941 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3942 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003946 vcol_save_attr = wlv.char_attr;
3947 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003948 }
3949 }
3950#endif
3951
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003952 if (wlv.draw_state == WL_LINE)
3953 vcol_prev = wlv.vcol;
3954
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003955 // Store character to be displayed.
3956 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003957 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958 {
3959 // Store the character.
3960#if defined(FEAT_RIGHTLEFT)
3961 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3962 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003963 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003964 --wlv.off;
3965 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003966 }
3967#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003968 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003969 if (enc_dbcs == DBCS_JPNU)
3970 {
3971 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003972 ScreenLines[wlv.off] = 0x8e;
3973 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974 }
3975 else if (enc_utf8)
3976 {
3977 if (mb_utf8)
3978 {
3979 int i;
3980
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003983 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003984 for (i = 0; i < Screen_mco; ++i)
3985 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003986 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987 if (u8cc[i] == 0)
3988 break;
3989 }
3990 }
3991 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003992 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003993 }
3994 if (multi_attr)
3995 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003996 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003997 multi_attr = 0;
3998 }
3999 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01004000 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004001
zeertzjqdb54e982023-09-21 16:33:09 +02004002 if (wlv.draw_state > WL_NR
4003#ifdef FEAT_DIFF
4004 && wlv.filler_todo <= 0
4005#endif
4006 )
4007 ScreenCols[wlv.off] = wlv.vcol;
4008 else
4009 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004010
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004011 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
4012 {
4013 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004014 ++wlv.off;
4015 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016 if (enc_utf8)
4017 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004018 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004019 else
4020 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004021 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02004022
Bram Moolenaar1306b362022-08-06 15:59:06 +01004023 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004024#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004025 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004026#endif
4027 )
zeertzjqdb54e982023-09-21 16:33:09 +02004028 ScreenCols[wlv.off] = ++wlv.vcol;
4029 else
4030 ScreenCols[wlv.off] = -1;
4031
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004032 // When "wlv.tocol" is halfway a character, set it to the end
4033 // of the character, otherwise highlighting won't stop.
4034 if (wlv.tocol == wlv.vcol)
4035 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01004036
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004037#ifdef FEAT_RIGHTLEFT
4038 if (wp->w_p_rl)
4039 {
4040 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004041 --wlv.off;
4042 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004043 }
4044#endif
4045 }
4046#ifdef FEAT_RIGHTLEFT
4047 if (wp->w_p_rl)
4048 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004049 --wlv.off;
4050 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004051 }
4052 else
4053#endif
4054 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004055 ++wlv.off;
4056 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 }
4058 }
4059#ifdef FEAT_CONCEAL
4060 else if (wp->w_p_cole > 0 && is_concealing)
4061 {
zeertzjq010e1532024-03-14 18:22:17 +01004062 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4063
zeertzjqb557f482023-08-22 22:07:34 +02004064 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004065 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004066 if (concealed_wide)
4067 {
4068 // When a double-width char is concealed,
4069 // need to advance one more virtual column.
4070 ++wlv.vcol;
4071 ++wlv.vcol_off_co;
4072 }
4073
Bram Moolenaar1306b362022-08-06 15:59:06 +01004074 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004075 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004076
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004077 if (wp->w_p_wrap)
4078 {
4079 // Special voodoo required if 'wrap' is on.
4080 //
4081 // Advance the column indicator to force the line
4082 // drawing to wrap early. This will make the line
4083 // take up the same screen space when parts are concealed,
4084 // so that cursor line computations aren't messed up.
4085 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004086 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004087 // trailing junk to be written out of the screen line
4088 // we are building, 'boguscols' keeps track of the number
4089 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004090 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004091 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004092 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004093# ifdef FEAT_RIGHTLEFT
4094 if (wp->w_p_rl)
4095 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004096 wlv.col -= wlv.n_extra;
4097 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004098 }
4099 else
4100# endif
4101 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004102 wlv.col += wlv.n_extra;
4103 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004105 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004106 n_attr = 0;
4107 }
4108
zeertzjq010e1532024-03-14 18:22:17 +01004109 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004110 {
4111 // Need to fill two screen columns.
4112# ifdef FEAT_RIGHTLEFT
4113 if (wp->w_p_rl)
4114 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004115 --wlv.boguscols;
4116 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004117 }
4118 else
4119# endif
4120 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004121 ++wlv.boguscols;
4122 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004123 }
4124 }
4125
4126# ifdef FEAT_RIGHTLEFT
4127 if (wp->w_p_rl)
4128 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004129 --wlv.boguscols;
4130 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131 }
4132 else
4133# endif
4134 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004135 ++wlv.boguscols;
4136 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004137 }
4138 }
4139 else
4140 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004141 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004142 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004143 wlv.vcol += wlv.n_extra;
4144 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004145 n_attr = 0;
4146 }
4147 }
4148
4149 }
4150#endif // FEAT_CONCEAL
4151 else
zeertzjqb557f482023-08-22 22:07:34 +02004152 --skip_cells;
4153
4154 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4155 {
4156 wlv.vcol += skipped_cells;
4157 skipped_cells = 0;
4158 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004160 // Only advance the "wlv.vcol" when after the 'number' or
4161 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004162 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004163#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004164 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004165#endif
4166 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004167 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004168
4169#ifdef FEAT_SYN_HL
4170 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004171 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004172#endif
4173
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004174 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004175 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4176 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004177
4178 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004179 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004180 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004181 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004182 if (wlv.n_attr_skip > 0)
4183 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004184
4185 // At end of screen line and there is more to come: Display the line
4186 // so far. If there is no more to display it is caught above.
4187 if ((
4188#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004189 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004190#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004191 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004192 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004193 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004194#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004195 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004196#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004197#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004198 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004199 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004200#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004201 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004202 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004203 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4204 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004205 )
4206 {
4207#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004208 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004209 // Apply 'cursorline' and 'wincolor' highlight.
4210 if (wlv.boguscols != 0 && (
4211# ifdef LINE_ATTR
4212 wlv.line_attr != 0 ||
4213# endif
4214 wlv.win_attr != 0
4215 )
4216 )
4217 {
4218 int attr = wlv.win_attr;
4219# ifdef LINE_ATTR
4220 if (wlv.line_attr != 0)
4221 attr = hl_combine_attr(attr, wlv.line_attr);
4222# endif
4223 while ((
4224# ifdef FEAT_RIGHTLEFT
4225 wp->w_p_rl ? wlv.col >= 0 :
4226# endif
4227 wlv.col < wp->w_width))
4228 {
4229 ScreenLines[wlv.off] = ' ';
4230 if (enc_utf8)
4231 ScreenLinesUC[wlv.off] = 0;
4232 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004233 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004234# ifdef FEAT_RIGHTLEFT
4235 if (wp->w_p_rl)
4236 {
4237 wlv.off--;
4238 wlv.col--;
4239 wlv.boguscols++;
4240 }
4241 else
4242# endif
4243 {
4244 wlv.off++;
4245 wlv.col++;
4246 wlv.boguscols--;
4247 }
4248 }
4249 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004250 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004251 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004252 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004253 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004254#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004255 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004256#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004257 ++wlv.row;
4258 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004259
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004260 // When not wrapping and finished diff lines, break here.
4261 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004262#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004263 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004264#endif
4265#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004266 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004267 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004268#endif
4269 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004270 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004271#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004272 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004273 {
4274 // do not output more of the line, only the "below" prop
John Marriottf51ff962024-06-02 19:44:11 +02004275 ptr = line + (size_t)ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004276# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004277 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004278# endif
4279 }
4280#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004281
4282 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004283 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004284#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004285 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004286#endif
4287 )
4288 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004289 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4290 draw_vsep_win(wp, wlv.row);
4291 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004292 }
4293
4294 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004295 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004296 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004297 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004298 break;
4299 }
4300
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004301 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004302#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004303 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004304#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004305#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004306 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004307#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004308 && wp->w_width == Columns)
4309 {
4310 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004311 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004312
4313 // Special trick to make copy/paste of wrapped lines work with
4314 // xterm/screen: write an extra character beyond the end of
4315 // the line. This will work with all terminal types
4316 // (regardless of the xn,am settings).
4317 // Only do this on a fast tty.
4318 // Only do this if the cursor is on the current line
4319 // (something has been written in it).
4320 // Don't do this for the GUI.
4321 // Don't do this for double-width characters.
4322 // Don't do this for a window not at the right screen border.
4323 if (p_tf
4324#ifdef FEAT_GUI
4325 && !gui.in_use
4326#endif
4327 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004328 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4329 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004330 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004331 || (*mb_off2cells)(
4332 LineOffset[wlv.screen_row - 1]
4333 + (int)Columns - 2,
4334 LineOffset[wlv.screen_row]
4335 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004336 {
4337 // First make sure we are at the end of the screen line,
4338 // then output the same character again to let the
4339 // terminal know about the wrap. If the terminal doesn't
4340 // auto-wrap, we overwrite the character.
4341 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004342 screen_char(LineOffset[wlv.screen_row - 1]
4343 + (unsigned)Columns - 1,
4344 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004345
4346 // When there is a multi-byte character, just output a
4347 // space to keep it simple.
4348 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004349 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004350 out_char(' ');
4351 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004352 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004353 + (Columns - 1)]);
4354 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004355 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004356 screen_start(); // don't know where cursor is now
4357 }
4358 }
4359
Bram Moolenaar1306b362022-08-06 15:59:06 +01004360 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004361
Bram Moolenaareed9d462021-02-15 20:38:25 +01004362 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004363#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004364 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004365# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004366 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004367# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004368 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004369 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004370#endif
4371#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004372 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004373 // When the filler lines are actually below the last line of the
4374 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004375 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004376 break;
4377#endif
4378 }
4379
4380 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004381#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004382 vim_free(text_props);
4383 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004384 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004385#endif
4386
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004387 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004388 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004389 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004390}