blob: ed02f3cab6db9bea4051180b757a4faf37dfbfbc [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;
42 static int prev_left_col;
43 static int prev_right_col;
44 static int prev_col_off;
45
46 int cur_col_off = win_col_off(wp);
47 int width1;
48 int width2;
49
50 if (saved_w_virtcol == wp->w_virtcol
51 && prev_wp == wp && prev_col_off == cur_col_off)
52 {
53 *right_col = prev_right_col;
54 *left_col = prev_left_col;
55 return;
56 }
57
58 width1 = wp->w_width - cur_col_off;
59 width2 = width1 + win_col_off2(wp);
60
61 *left_col = 0;
62 *right_col = width1;
63
64 if (wp->w_virtcol >= (colnr_T)width1)
65 *right_col = width1 + ((wp->w_virtcol - width1) / width2 + 1) * width2;
66 if (wp->w_virtcol >= (colnr_T)width1 && width2 > 0)
67 *left_col = (wp->w_virtcol - width1) / width2 * width2 + width1;
68
69 // cache values
70 prev_left_col = *left_col;
71 prev_right_col = *right_col;
72 prev_wp = wp;
73 saved_w_virtcol = wp->w_virtcol;
74 prev_col_off = cur_col_off;
75}
76#endif
77
Bram Moolenaar45e4eea2022-12-01 18:38:02 +000078#if defined(FEAT_SIGNS) || defined(FEAT_QUICKFIX) \
79 || defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
80// using an attribute for the whole line
81# define LINE_ATTR
82#endif
83
Bram Moolenaar1306b362022-08-06 15:59:06 +010084// structure with variables passed between win_line() and other functions
85typedef struct {
86 int draw_state; // what to draw next
87
88 linenr_T lnum; // line number to be drawn
89
90 int startrow; // first row in the window to be drawn
91 int row; // row in the window, excl w_winrow
92 int screen_row; // row on the screen, incl w_winrow
93
94 long vcol; // virtual column, before wrapping
95 int col; // visual column on screen, after wrapping
96#ifdef FEAT_CONCEAL
97 int boguscols; // nonexistent columns added to "col" to force
98 // wrapping
Bram Moolenaarf53e0652023-02-19 14:16:02 +000099 int vcol_off_co; // offset for concealed characters
Bram Moolenaar1306b362022-08-06 15:59:06 +0100100#endif
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000101 int vcol_off_tp; // offset for virtual text
Bram Moolenaar1306b362022-08-06 15:59:06 +0100102#ifdef FEAT_SYN_HL
103 int draw_color_col; // highlight colorcolumn
104 int *color_cols; // pointer to according columns array
105#endif
106 int eol_hl_off; // 1 if highlighted char after EOL
107
108 unsigned off; // offset in ScreenLines/ScreenAttrs
109
110 int win_attr; // background for the whole window, except
111 // margins and "~" lines.
Bram Moolenaard7657e92022-09-20 18:59:30 +0100112 int wcr_attr; // attributes from 'wincolor'
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100113#ifdef FEAT_SYN_HL
114 int cul_attr; // set when 'cursorline' active
115#endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000116#ifdef LINE_ATTR
117 int line_attr; // for the whole line, includes 'cursorline'
118#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100119
120 int screen_line_flags; // flags for screen_line()
121
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100122 int fromcol; // start of inverting
123 int tocol; // end of inverting
124
125#ifdef FEAT_LINEBREAK
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100126 long vcol_sbr; // virtual column after showbreak
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100127 int need_showbreak; // overlong line, skipping first x chars
128 int dont_use_showbreak; // do not use 'showbreak'
129#endif
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100130#ifdef FEAT_PROP_POPUP
131 int text_prop_above_count;
132#endif
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100133
Bram Moolenaar1306b362022-08-06 15:59:06 +0100134 // TRUE when 'cursorlineopt' has "screenline" and cursor is in this line
135 int cul_screenline;
136
137 int char_attr; // attributes for the next character
138
139 int n_extra; // number of extra bytes
140 char_u *p_extra; // string of extra chars, plus NUL, only used
141 // when c_extra and c_final are NUL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100142 char_u *p_extra_free; // p_extra buffer that needs to be freed
Bram Moolenaaree28c702022-11-17 14:56:00 +0000143 int extra_attr; // attributes for p_extra, should be combined
144 // with win_attr if needed
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000145 int n_attr_skip; // chars to skip before using extra_attr
Bram Moolenaar1306b362022-08-06 15:59:06 +0100146 int c_extra; // extra chars, all the same
147 int c_final; // final char, mandatory if set
zeertzjq6e940d92023-08-17 23:21:40 +0200148 int extra_for_textprop; // n_extra set for textprop
149 int start_extra_for_textprop; // extra_for_textprop was just set
Bram Moolenaar1306b362022-08-06 15:59:06 +0100150
151 // saved "extra" items for when draw_state becomes WL_LINE (again)
152 int saved_n_extra;
153 char_u *saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +0100154 char_u *saved_p_extra_free;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000155 int saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000156 int saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +0000157 int saved_extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100158 int saved_c_extra;
159 int saved_c_final;
160 int saved_char_attr;
161
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100162 char_u extra[NUMBUFLEN + MB_MAXBYTES];
163 // "%ld " and 'fdc' must fit in here, as well
164 // any text sign
Bram Moolenaard7657e92022-09-20 18:59:30 +0100165
Bram Moolenaar1306b362022-08-06 15:59:06 +0100166#ifdef FEAT_DIFF
167 hlf_T diff_hlf; // type of diff highlighting
168#endif
Bram Moolenaard7657e92022-09-20 18:59:30 +0100169 int filler_lines; // nr of filler lines to be drawn
170 int filler_todo; // nr of filler lines still to do + 1
171#ifdef FEAT_SIGNS
172 sign_attrs_T sattr;
173#endif
Christian Brabandtdd75fcf2023-10-11 21:51:19 +0200174#ifdef FEAT_LINEBREAK
175 // do consider wrapping in linebreak mode only after encountering
176 // a non whitespace char
177 int need_lbr;
178#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +0100179} winlinevars_T;
180
181// draw_state values for items that are drawn in sequence:
182#define WL_START 0 // nothing done yet, must be zero
Martin Tournoij7904fa42022-10-04 16:28:45 +0100183#define WL_CMDLINE (WL_START + 1) // cmdline window column
Bram Moolenaar1306b362022-08-06 15:59:06 +0100184#ifdef FEAT_FOLDING
185# define WL_FOLD (WL_CMDLINE + 1) // 'foldcolumn'
186#else
187# define WL_FOLD WL_CMDLINE
188#endif
189#ifdef FEAT_SIGNS
190# define WL_SIGN (WL_FOLD + 1) // column for signs
191#else
192# define WL_SIGN WL_FOLD // column for signs
193#endif
194#define WL_NR (WL_SIGN + 1) // line number
195#ifdef FEAT_LINEBREAK
196# define WL_BRI (WL_NR + 1) // 'breakindent'
197#else
198# define WL_BRI WL_NR
199#endif
200#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
201# define WL_SBR (WL_BRI + 1) // 'showbreak' or 'diff'
202#else
203# define WL_SBR WL_BRI
204#endif
205#define WL_LINE (WL_SBR + 1) // text in the line
206
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100207#if defined(FEAT_SIGNS) || defined(FEAT_FOLDING)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200208/*
Bram Moolenaare413ea02021-11-24 16:20:13 +0000209 * Return TRUE if CursorLineSign highlight is to be used.
210 */
211 static int
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100212use_cursor_line_highlight(win_T *wp, linenr_T lnum)
Bram Moolenaare413ea02021-11-24 16:20:13 +0000213{
214 return wp->w_p_cul
215 && lnum == wp->w_cursor.lnum
216 && (wp->w_p_culopt_flags & CULOPT_NBR);
217}
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100218#endif
Bram Moolenaare413ea02021-11-24 16:20:13 +0000219
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100220
221#ifdef FEAT_FOLDING
222/*
223 * Setup for drawing the 'foldcolumn', if there is one.
224 */
225 static void
226handle_foldcolumn(win_T *wp, winlinevars_T *wlv)
227{
228 int fdc = compute_foldcolumn(wp, 0);
229
230 if (fdc <= 0)
231 return;
232
233 // Allocate a buffer, "wlv->extra[]" may already be in use.
234 vim_free(wlv->p_extra_free);
235 wlv->p_extra_free = alloc(MAX_MCO * fdc + 1);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000236 if (wlv->p_extra_free == NULL)
237 return;
238
239 wlv->n_extra = (int)fill_foldcolumn(wlv->p_extra_free,
zeertzjq58e1e012023-06-04 18:46:28 +0100240 wp, FALSE, wlv->lnum);
Yegappan Lakshmanan465de3a2022-12-26 12:50:04 +0000241 wlv->p_extra_free[wlv->n_extra] = NUL;
242 wlv->p_extra = wlv->p_extra_free;
243 wlv->c_extra = NUL;
244 wlv->c_final = NUL;
245 if (use_cursor_line_highlight(wp, wlv->lnum))
246 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLF));
247 else
248 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_FC));
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100249}
250#endif
251
252#ifdef FEAT_SIGNS
Bram Moolenaare413ea02021-11-24 16:20:13 +0000253/*
Bram Moolenaard7657e92022-09-20 18:59:30 +0100254 * Get information needed to display the sign in line "wlv->lnum" in window
255 * "wp".
256 * If "nrcol" is TRUE, the sign is going to be displayed in the number column.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200257 * Otherwise the sign is going to be displayed in the sign column.
258 */
259 static void
260get_sign_display_info(
261 int nrcol,
262 win_T *wp,
Bram Moolenaard7657e92022-09-20 18:59:30 +0100263 winlinevars_T *wlv)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200264{
265 int text_sign;
266# ifdef FEAT_SIGN_ICONS
267 int icon_sign;
268# endif
269
270 // Draw two cells with the sign value or blank.
Bram Moolenaar1306b362022-08-06 15:59:06 +0100271 wlv->c_extra = ' ';
272 wlv->c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200273 if (nrcol)
Bram Moolenaar1306b362022-08-06 15:59:06 +0100274 wlv->n_extra = number_width(wp) + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200275 else
276 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100277 if (use_cursor_line_highlight(wp, wlv->lnum))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100278 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLS));
Bram Moolenaare413ea02021-11-24 16:20:13 +0000279 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100280 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_SC));
Bram Moolenaar1306b362022-08-06 15:59:06 +0100281 wlv->n_extra = 2;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200282 }
283
Bram Moolenaar1306b362022-08-06 15:59:06 +0100284 if (wlv->row == wlv->startrow
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200285#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +0100286 + wlv->filler_lines && wlv->filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200287#endif
288 )
289 {
Bram Moolenaard7657e92022-09-20 18:59:30 +0100290 text_sign = (wlv->sattr.sat_text != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200291# ifdef FEAT_SIGN_ICONS
Bram Moolenaard7657e92022-09-20 18:59:30 +0100292 icon_sign = (wlv->sattr.sat_icon != NULL) ? wlv->sattr.sat_typenr : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200293 if (gui.in_use && icon_sign != 0)
294 {
295 // Use the image in this position.
296 if (nrcol)
297 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100298 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100299 sprintf((char *)wlv->extra, "%-*c ",
300 number_width(wp), SIGN_BYTE);
301 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100302 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200303 }
304 else
Bram Moolenaar1306b362022-08-06 15:59:06 +0100305 wlv->c_extra = SIGN_BYTE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200306# ifdef FEAT_NETBEANS_INTG
Bram Moolenaard7657e92022-09-20 18:59:30 +0100307 if (netbeans_active() && (buf_signcount(wp->w_buffer, wlv->lnum)
308 > 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200309 {
310 if (nrcol)
311 {
Bram Moolenaar1306b362022-08-06 15:59:06 +0100312 wlv->c_extra = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100313 sprintf((char *)wlv->extra, "%-*c ", number_width(wp),
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200314 MULTISIGN_BYTE);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100315 wlv->p_extra = wlv->extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +0100316 wlv->n_extra = (int)STRLEN(wlv->p_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;
335 int n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200336
337 for (n = 0; n < width; n++)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100338 wlv->extra[n] = ' ';
Bram Moolenaar2b1ddf12022-09-21 11:21:57 +0100339 vim_snprintf((char *)wlv->extra + n,
340 sizeof(wlv->extra) - n, "%s ", wlv->p_extra);
Bram Moolenaard7657e92022-09-20 18:59:30 +0100341 wlv->p_extra = wlv->extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200342 }
Bram Moolenaar1306b362022-08-06 15:59:06 +0100343 wlv->c_extra = NUL;
344 wlv->c_final = NUL;
345 wlv->n_extra = (int)STRLEN(wlv->p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200346 }
Bram Moolenaare413ea02021-11-24 16:20:13 +0000347
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100348 if (use_cursor_line_highlight(wp, wlv->lnum)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100349 && wlv->sattr.sat_culhl > 0)
350 wlv->char_attr = wlv->sattr.sat_culhl;
Bram Moolenaare413ea02021-11-24 16:20:13 +0000351 else
Bram Moolenaard7657e92022-09-20 18:59:30 +0100352 wlv->char_attr = wlv->sattr.sat_texthl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200353 }
354 }
355}
356#endif
357
Bram Moolenaard7657e92022-09-20 18:59:30 +0100358/*
359 * Display the absolute or relative line number. After the first row fill with
360 * blanks when the 'n' flag isn't in 'cpo'.
361 */
362 static void
363handle_lnum_col(
364 win_T *wp,
365 winlinevars_T *wlv,
366 int sign_present UNUSED,
Bram Moolenaar31724232022-09-20 20:25:36 +0100367 int num_attr UNUSED)
Bram Moolenaard7657e92022-09-20 18:59:30 +0100368{
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100369 int has_cpo_n = vim_strchr(p_cpo, CPO_NUMCOL) != NULL;
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100370 int lnum_row = wlv->startrow + wlv->filler_lines
371#ifdef FEAT_PROP_POPUP
372 + wlv->text_prop_above_count
373#endif
374 ;
Bram Moolenaar35b251d2022-10-06 20:18:16 +0100375
Bram Moolenaard7657e92022-09-20 18:59:30 +0100376 if ((wp->w_p_nu || wp->w_p_rnu)
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100377 && (wlv->row <= lnum_row || !has_cpo_n)
Bram Moolenaar37251162022-10-06 20:48:00 +0100378 // there is no line number in a wrapped line when "n" is in
379 // 'cpoptions', but 'breakindent' assumes it anyway.
380 && !((has_cpo_n
381#ifdef FEAT_LINEBREAK
382 && !wp->w_p_bri
383#endif
384 ) && wp->w_skipcol > 0 && wlv->lnum == wp->w_topline))
Bram Moolenaard7657e92022-09-20 18:59:30 +0100385 {
386#ifdef FEAT_SIGNS
387 // If 'signcolumn' is set to 'number' and a sign is present
388 // in 'lnum', then display the sign instead of the line
389 // number.
390 if ((*wp->w_p_scl == 'n' && *(wp->w_p_scl + 1) == 'u') && sign_present)
391 get_sign_display_info(TRUE, wp, wlv);
392 else
393#endif
394 {
395 // Draw the line number (empty space after wrapping).
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100396 // When there are text properties above the line put the line number
397 // below them.
Bram Moolenaarb99e6e62022-10-17 18:55:03 +0100398 if (wlv->row == lnum_row
zeertzjq88bb3e02023-05-02 20:52:59 +0100399 && (wp->w_skipcol == 0 || wlv->row > 0
Bram Moolenaareb4de622022-10-15 13:42:17 +0100400 || (wp->w_p_nu && wp->w_p_rnu)))
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100401 {
402 long num;
403 char *fmt = "%*ld ";
404
405 if (wp->w_p_nu && !wp->w_p_rnu)
406 // 'number' + 'norelativenumber'
407 num = (long)wlv->lnum;
408 else
409 {
410 // 'relativenumber', don't use negative numbers
411 num = labs((long)get_cursor_rel_lnum(wp, wlv->lnum));
412 if (num == 0 && wp->w_p_nu && wp->w_p_rnu)
413 {
414 // 'number' + 'relativenumber'
415 num = wlv->lnum;
416 fmt = "%-*ld ";
417 }
418 }
419
420 sprintf((char *)wlv->extra, fmt, number_width(wp), num);
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100421 if (wp->w_skipcol > 0 && wlv->startrow == 0)
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100422 for (wlv->p_extra = wlv->extra; *wlv->p_extra == ' ';
423 ++wlv->p_extra)
424 *wlv->p_extra = '-';
425#ifdef FEAT_RIGHTLEFT
426 if (wp->w_p_rl) // reverse line numbers
427 {
428 char_u *p1, *p2;
429 int t;
430
431 // like rl_mirror(), but keep the space at the end
432 p2 = skipwhite(wlv->extra);
433 p2 = skiptowhite(p2) - 1;
434 for (p1 = skipwhite(wlv->extra); p1 < p2; ++p1, --p2)
435 {
436 t = *p1;
437 *p1 = *p2;
438 *p2 = t;
439 }
440 }
441#endif
442 wlv->p_extra = wlv->extra;
443 wlv->c_extra = NUL;
444 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100445 }
446 else
447 {
Bram Moolenaarec5e1482022-09-21 16:38:13 +0100448 wlv->c_extra = ' ';
449 wlv->c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +0100450 }
451 wlv->n_extra = number_width(wp) + 1;
452 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_N));
453#ifdef FEAT_SYN_HL
454 // When 'cursorline' is set highlight the line number of
455 // the current line differently.
456 // When 'cursorlineopt' does not have "line" only
457 // highlight the line number itself.
458 // TODO: Can we use CursorLine instead of CursorLineNr
459 // when CursorLineNr isn't set?
460 if (wp->w_p_cul
461 && wlv->lnum == wp->w_cursor.lnum
462 && (wp->w_p_culopt_flags & CULOPT_NBR)
463 && (wlv->row == wlv->startrow + wlv->filler_lines
464 || (wlv->row > wlv->startrow + wlv->filler_lines
465 && (wp->w_p_culopt_flags & CULOPT_LINE))))
466 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_CLN));
467#endif
468 if (wp->w_p_rnu && wlv->lnum < wp->w_cursor.lnum
469 && HL_ATTR(HLF_LNA) != 0)
470 // Use LineNrAbove
471 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNA));
472 if (wp->w_p_rnu && wlv->lnum > wp->w_cursor.lnum
473 && HL_ATTR(HLF_LNB) != 0)
474 // Use LineNrBelow
475 wlv->char_attr = hl_combine_attr(wlv->wcr_attr, HL_ATTR(HLF_LNB));
476 }
477#ifdef FEAT_SIGNS
478 if (num_attr)
479 wlv->char_attr = num_attr;
480#endif
481 }
482}
Bram Moolenaar2d2e25b2022-09-20 21:09:42 +0100483
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100484#ifdef FEAT_LINEBREAK
485 static void
486handle_breakindent(win_T *wp, winlinevars_T *wlv)
487{
488 if (wp->w_briopt_sbr && wlv->draw_state == WL_BRI - 1
Bram Moolenaar9466fb82022-10-11 14:54:42 +0100489 && *get_showbreak_value(wp) != NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100490 // draw indent after showbreak value
491 wlv->draw_state = WL_BRI;
492 else if (wp->w_briopt_sbr && wlv->draw_state == WL_SBR)
493 // After the showbreak, draw the breakindent
494 wlv->draw_state = WL_BRI - 1;
495
496 // draw 'breakindent': indent wrapped text accordingly
497 if (wlv->draw_state == WL_BRI - 1)
498 {
499 wlv->draw_state = WL_BRI;
500 // if wlv->need_showbreak is set, breakindent also applies
zeertzjq588f20d2023-12-05 15:47:09 +0100501 if (wp->w_p_bri && (wlv->row > wlv->startrow
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100502# ifdef FEAT_DIFF
zeertzjq588f20d2023-12-05 15:47:09 +0100503 + wlv->filler_lines
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100504# endif
zeertzjq588f20d2023-12-05 15:47:09 +0100505 || wlv->need_showbreak)
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100506# ifdef FEAT_PROP_POPUP
507 && !wlv->dont_use_showbreak
508# endif
509 )
510 {
511 wlv->char_attr = 0;
512# ifdef FEAT_DIFF
513 if (wlv->diff_hlf != (hlf_T)0)
514 wlv->char_attr = HL_ATTR(wlv->diff_hlf);
515# endif
516 wlv->p_extra = NULL;
517 wlv->c_extra = ' ';
518 wlv->c_final = NUL;
519 wlv->n_extra = get_breakindent_win(wp,
520 ml_get_buf(wp->w_buffer, wlv->lnum, FALSE));
521 if (wlv->row == wlv->startrow)
522 {
523 wlv->n_extra -= win_col_off2(wp);
524 if (wlv->n_extra < 0)
525 wlv->n_extra = 0;
526 }
zeertzjq23627722023-12-27 19:08:53 +0100527
528 // Correct start of highlighted area for 'breakindent',
529 if (wlv->fromcol >= wlv->vcol
530 && wlv->fromcol < wlv->vcol + wlv->n_extra)
531 wlv->fromcol = wlv->vcol + wlv->n_extra;
532
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100533 // Correct end of highlighted area for 'breakindent',
534 // required when 'linebreak' is also set.
535 if (wlv->tocol == wlv->vcol)
536 wlv->tocol += wlv->n_extra;
537 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100538
539 if (wp->w_skipcol > 0 && wlv->startrow == 0 && wp->w_p_wrap
540 && wp->w_briopt_sbr)
541 wlv->need_showbreak = FALSE;
Bram Moolenaarc20a4192022-09-21 14:34:28 +0100542 }
543}
544#endif
545
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100546#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
547 static void
548handle_showbreak_and_filler(win_T *wp, winlinevars_T *wlv)
549{
550# ifdef FEAT_DIFF
551 if (wlv->filler_todo > 0)
552 {
553 // Draw "deleted" diff line(s).
554 if (char2cells(wp->w_fill_chars.diff) > 1)
555 {
556 wlv->c_extra = '-';
557 wlv->c_final = NUL;
558 }
559 else
560 {
561 wlv->c_extra = wp->w_fill_chars.diff;
562 wlv->c_final = NUL;
563 }
564# ifdef FEAT_RIGHTLEFT
565 if (wp->w_p_rl)
566 wlv->n_extra = wlv->col + 1;
567 else
568# endif
569 wlv->n_extra = wp->w_width - wlv->col;
570 wlv->char_attr = HL_ATTR(HLF_DED);
571 }
572# endif
573
574# ifdef FEAT_LINEBREAK
575 char_u *sbr = get_showbreak_value(wp);
576 if (*sbr != NUL && wlv->need_showbreak)
577 {
578 // Draw 'showbreak' at the start of each broken line.
579 wlv->p_extra = sbr;
580 wlv->c_extra = NUL;
581 wlv->c_final = NUL;
582 wlv->n_extra = (int)STRLEN(sbr);
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100583 wlv->vcol_sbr = wlv->vcol + MB_CHARLEN(sbr);
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100584
585 // Correct start of highlighted area for 'showbreak'.
586 if (wlv->fromcol >= wlv->vcol && wlv->fromcol < wlv->vcol_sbr)
587 wlv->fromcol = wlv->vcol_sbr;
588
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100589 // Correct end of highlighted area for 'showbreak',
590 // required when 'linebreak' is also set.
591 if (wlv->tocol == wlv->vcol)
zeertzjqdf23d7f2024-02-09 18:14:12 +0100592 wlv->tocol = wlv->vcol_sbr;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100593 // combine 'showbreak' with 'wincolor'
594 wlv->char_attr = hl_combine_attr(wlv->win_attr, HL_ATTR(HLF_AT));
595# ifdef FEAT_SYN_HL
596 // combine 'showbreak' with 'cursorline'
597 if (wlv->cul_attr != 0)
598 wlv->char_attr = hl_combine_attr(wlv->char_attr, wlv->cul_attr);
599# endif
600 }
zeertzjq7e4f62a2023-12-28 23:19:52 +0100601
602 if (wp->w_skipcol == 0 || wlv->startrow > 0 || !wp->w_p_wrap
603 || !wp->w_briopt_sbr)
604 wlv->need_showbreak = FALSE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +0100605# endif
606}
607#endif
608
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100609#if defined(FEAT_PROP_POPUP) || defined(PROTO)
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100610/*
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100611 * Return the cell size of virtual text after truncation.
612 */
613 static int
614textprop_size_after_trunc(
615 win_T *wp,
616 int flags, // TP_FLAG_ALIGN_*
617 int added,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100618 int padding,
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100619 char_u *text,
620 int *n_used_ptr)
621{
622 int space = (flags & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_ABOVE))
Bram Moolenaar1206c162022-10-10 15:40:04 +0100623 ? wp->w_width - win_col_off(wp) : added;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100624 int len = (int)STRLEN(text);
625 int strsize = 0;
626 int n_used;
627
Bram Moolenaar7e017462022-10-11 21:02:09 +0100628 // if the remaining size is to small and 'wrap' is set we wrap anyway and
629 // 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;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100634 for (n_used = 0; n_used < len; n_used += (*mb_ptr2len)(text + n_used))
635 {
636 int clen = ptr2cells(text + n_used);
637
638 if (strsize + clen > space)
639 break;
640 strsize += clen;
641 }
642 *n_used_ptr = n_used;
643 return strsize;
644}
645
646/*
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100647 * Take care of padding, right-align and truncation of virtual text after a
648 * line.
649 * if "n_attr" is not NULL then "n_extra" and "p_extra" are adjusted for any
650 * padding, right-align and truncation. Otherwise only the size is computed.
651 * When "n_attr" is NULL returns the number of screen cells used.
652 * Otherwise returns TRUE when drawing continues on the next line.
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100653 */
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100654 int
655text_prop_position(
656 win_T *wp,
657 textprop_T *tp,
porygonisaduck38854b52022-11-27 20:55:05 +0000658 int vcol, // current text column
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100659 int scr_col, // current screen column
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100660 int *n_extra, // nr of bytes for virtual text
661 char_u **p_extra, // virtual text
662 int *n_attr, // attribute cells, NULL if not used
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000663 int *n_attr_skip, // cells to skip attr, NULL if not used
664 int do_skip) // skip_cells is not zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200665{
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100666 int right = (tp->tp_flags & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100667 int above = (tp->tp_flags & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100668 int below = (tp->tp_flags & TP_FLAG_ALIGN_BELOW);
Bram Moolenaar1aeb3eb2023-01-01 14:04:51 +0000669 int wrap = tp->tp_col < MAXCOL || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100670 int padding = tp->tp_col == MAXCOL && tp->tp_len > 1
porygonisaduck38854b52022-11-27 20:55:05 +0000671 ? tp->tp_len - 1 : 0;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +0100672 int col_with_padding = scr_col + (below ? 0 : padding);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100673 int room = wp->w_width - col_with_padding;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100674 int before = room; // spaces before the text
675 int after = 0; // spaces after the text
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100676 int n_used = *n_extra;
677 char_u *l = NULL;
678 int strsize = vim_strsize(*p_extra);
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100679 int cells = wrap ? strsize : textprop_size_after_trunc(wp,
Bram Moolenaar13845c42022-10-09 15:26:03 +0100680 tp->tp_flags, before, padding, *p_extra, &n_used);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200681
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100682 if (wrap || right || above || below || padding > 0 || n_used < *n_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100683 {
Bram Moolenaarccf28372022-10-10 21:10:03 +0100684 int col_off = win_col_off(wp) - win_col_off2(wp);
Bram Moolenaarb84d5652022-09-20 17:57:53 +0100685
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100686 if (above)
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100687 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100688 before = 0;
Bram Moolenaar79f8b842022-09-11 13:31:01 +0100689 after = wp->w_width - cells - win_col_off(wp) - padding;
Bram Moolenaar2354b662023-04-23 21:42:25 +0100690 if (after < 0)
691 {
692 // text "above" has too much padding to fit
693 padding += after;
694 after = 0;
695 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100696 }
697 else
698 {
699 // Right-align: fill with before
700 if (right)
701 before -= cells;
porygonisaduck38854b52022-11-27 20:55:05 +0000702
703 // Below-align: empty line add one character
Bram Moolenaar7c02ad92022-11-29 21:37:13 +0000704 if (below && vcol == 0 && col_with_padding == col_off
705 && wp->w_width - col_off == before)
706 col_with_padding += 1;
porygonisaduck38854b52022-11-27 20:55:05 +0000707
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100708 if (before < 0
709 || !(right || below)
porygonisaduck38854b52022-11-27 20:55:05 +0000710 || (below ? (col_with_padding <= col_off || !wp->w_p_wrap)
711 : (n_used < *n_extra)))
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100712 {
Bram Moolenaar7e017462022-10-11 21:02:09 +0100713 if (right && (wrap
714 || (room < PROP_TEXT_MIN_CELLS && wp->w_p_wrap)))
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100715 {
716 // right-align on next line instead of wrapping if possible
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100717 before = wp->w_width - col_off - strsize + room;
718 if (before < 0)
719 before = 0;
720 else
721 n_used = *n_extra;
722 }
Bram Moolenaar56a40fe2022-12-06 14:17:57 +0000723 else if (below && before > vcol && do_skip)
724 before -= vcol;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100725 else
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100726 before = 0;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100727 }
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100728 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100729
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100730 // With 'nowrap' add one to show the "extends" character if needed (it
731 // doesn't show if the text just fits).
732 if (!wp->w_p_wrap
733 && n_used < *n_extra
734 && wp->w_lcs_chars.ext != NUL
735 && wp->w_p_list)
736 ++n_used;
737
738 // add 1 for NUL, 2 for when '…' is used
739 if (n_attr != NULL)
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200740 l = alloc(n_used + before + after + (padding > 0 ? padding : 0) + 3);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100741 if (n_attr == NULL || l != NULL)
742 {
743 int off = 0;
744
745 if (n_attr != NULL)
746 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100747 vim_memset(l, ' ', before);
748 off += before;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100749 if (padding > 0)
750 {
751 vim_memset(l + off, ' ', padding);
752 off += padding;
753 }
754 vim_strncpy(l + off, *p_extra, n_used);
755 off += n_used;
756 }
757 else
758 {
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100759 off = before + after + padding + n_used;
760 cells += before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100761 }
762 if (n_attr != NULL)
763 {
764 if (n_used < *n_extra && wp->w_p_wrap)
765 {
766 char_u *lp = l + off - 1;
767
768 if (has_mbyte)
769 {
h-east4c42c7e2023-04-17 21:44:57 +0100770 char_u buf[MB_MAXBYTES + 1];
771 char_u *cp = buf;
772
773 // change the last character to '…', converted to the
774 // current 'encoding'
775 STRCPY(buf, "…");
776 if (!enc_utf8)
777 {
778 vimconv_T vc;
779
780 vc.vc_type = CONV_NONE;
781 convert_setup(&vc, (char_u *)"utf-8", p_enc);
782 if (vc.vc_type != CONV_NONE)
783 {
784 cp = string_convert(&vc, buf, NULL);
785 if (cp == NULL)
786 {
787 // when conversion fails use '>'
788 cp = buf;
789 STRCPY(buf, ">");
790 }
791 convert_setup(&vc, NULL, NULL);
792 }
793 }
794
795 lp -= (*mb_ptr2cells)(cp) - 1;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100796 lp -= (*mb_head_off)(l, lp);
h-east4c42c7e2023-04-17 21:44:57 +0100797 STRCPY(lp, cp);
Bram Moolenaar13845c42022-10-09 15:26:03 +0100798 n_used = lp - l + 3 - before - padding;
h-east4c42c7e2023-04-17 21:44:57 +0100799 if (cp != buf)
800 vim_free(cp);
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100801 }
802 else
803 // change last character to '>'
804 *lp = '>';
805 }
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100806 else if (after > 0)
807 {
808 vim_memset(l + off, ' ', after);
809 l[off + after] = NUL;
810 }
811
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100812 *p_extra = l;
Bram Moolenaar04e0ed12022-09-10 20:00:56 +0100813 *n_extra = n_used + before + after + padding;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100814 *n_attr = mb_charlen(*p_extra);
Bram Moolenaar37f088e2022-12-02 21:50:14 +0000815 // n_attr_skip will not be decremented before draw_state is
816 // WL_LINE
Christian Brabandtf1cc4d52023-08-12 00:14:14 +0200817 *n_attr_skip = before + (padding > 0 ? padding : 0);
zeertzjq9352c282024-03-14 18:16:56 +0100818 *n_attr -= *n_attr_skip;
819 if (above)
820 *n_attr -= after;
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100821 }
822 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +0100823 }
Bram Moolenaar952c9b02022-08-10 16:00:33 +0100824
Bram Moolenaarf396ce82022-08-23 18:39:37 +0100825 if (n_attr == NULL)
826 return cells;
827 return (below && col_with_padding > win_col_off(wp) && !wp->w_p_wrap);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +0200828}
829#endif
830
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100831/*
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100832 * Call screen_line() using values from "wlv".
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100833 * Also takes care of putting "<<<" on the first line for 'smoothscroll'
834 * when 'showbreak' is not set.
zeertzjqd0c1b772024-03-16 15:03:33 +0100835 * When "clear_end" is TRUE clear until the end of the screen line.
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100836 */
837 static void
zeertzjqd0c1b772024-03-16 15:03:33 +0100838wlv_screen_line(win_T *wp, winlinevars_T *wlv, int clear_end)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100839{
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100840 if (wlv->row == 0 && wp->w_skipcol > 0
841#if defined(FEAT_LINEBREAK)
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100842 // do not overwrite the 'showbreak' text with "<<<"
Bram Moolenaar0937b9f2022-10-06 21:24:34 +0100843 && *get_showbreak_value(wp) == NUL
844#endif
Bram Moolenaar13cdde32022-10-15 14:07:48 +0100845 // do not overwrite the 'listchars' "precedes" text with "<<<"
846 && !(wp->w_p_list && wp->w_lcs_chars.prec != 0))
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100847 {
848 int off = (int)(current_ScreenLine - ScreenLines);
zeertzjqecb87dd2023-06-03 19:45:06 +0100849 int max_off = off + screen_Columns;
Bram Moolenaareb4de622022-10-15 13:42:17 +0100850 int skip = 0;
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100851
Bram Moolenaareb4de622022-10-15 13:42:17 +0100852 if (wp->w_p_nu && wp->w_p_rnu)
853 // Do not overwrite the line number, change "123 text" to
Bram Moolenaarf578ca22023-06-10 19:40:30 +0100854 // "123<<<xt".
Bram Moolenaareb4de622022-10-15 13:42:17 +0100855 while (skip < wp->w_width && VIM_ISDIGIT(ScreenLines[off]))
856 {
857 ++off;
858 ++skip;
859 }
860
861 for (int i = 0; i < 3 && i + skip < wp->w_width; ++i)
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100862 {
zeertzjqecb87dd2023-06-03 19:45:06 +0100863 if ((*mb_off2cells)(off, max_off) > 1)
864 // When the first half of a double-width character is
865 // overwritten, change the second half to a space.
866 ScreenLines[off + 1] = ' ';
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100867 ScreenLines[off] = '<';
868 if (enc_utf8)
869 ScreenLinesUC[off] = 0;
870 ScreenAttrs[off] = HL_ATTR(HLF_AT);
871 ++off;
872 }
873 }
874
875 screen_line(wp, wlv->screen_row, wp->w_wincol, wlv->col,
zeertzjqd0c1b772024-03-16 15:03:33 +0100876 clear_end ? wp->w_width : -wp->w_width,
877 wlv->vcol - 1, wlv->screen_line_flags);
Bram Moolenaar406b5d82022-10-03 16:44:12 +0100878}
879
880/*
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100881 * Called when finished with the line: draw the screen line and handle any
882 * highlighting until the right of the window.
883 */
884 static void
885draw_screen_line(win_T *wp, winlinevars_T *wlv)
886{
887#ifdef FEAT_SYN_HL
888 long v;
zeertzjqf6272552024-03-17 10:01:47 +0100889 int wcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100890
891 // Highlight 'cursorcolumn' & 'colorcolumn' past end of the line.
892 if (wp->w_p_wrap)
Bram Moolenaarf6196f42022-10-02 21:29:55 +0100893 v = wlv->startrow == 0 ? wp->w_skipcol : 0;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100894 else
895 v = wp->w_leftcol;
896
zeertzjqf6272552024-03-17 10:01:47 +0100897 wcol =
898# ifdef FEAT_RIGHTLEFT
899 wp->w_p_rl ? wp->w_width - wlv->col - 1 :
900# endif
901 wlv->col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100902 // check if line ends before left margin
zeertzjqf6272552024-03-17 10:01:47 +0100903 if (wlv->vcol < v + wcol - win_col_off(wp))
904 wlv->vcol = v + wcol - win_col_off(wp);
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100905# ifdef FEAT_CONCEAL
906 // Get rid of the boguscols now, we want to draw until the right
907 // edge for 'cursorcolumn'.
908 wlv->col -= wlv->boguscols;
909 wlv->boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000910# define VCOL_HLC (wlv->vcol - wlv->vcol_off_co - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100911# else
Bram Moolenaarf53e0652023-02-19 14:16:02 +0000912# define VCOL_HLC (wlv->vcol - wlv->vcol_off_tp)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100913# endif
914
915 if (wlv->draw_color_col)
916 wlv->draw_color_col = advance_color_col(VCOL_HLC, &wlv->color_cols);
917
918 if (((wp->w_p_cuc
919 && (int)wp->w_virtcol >= VCOL_HLC - wlv->eol_hl_off
920 && (int)wp->w_virtcol <
921 (long)wp->w_width * (wlv->row - wlv->startrow + 1) + v
922 && wlv->lnum != wp->w_cursor.lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000923 || wlv->draw_color_col
924# ifdef LINE_ATTR
925 || wlv->line_attr != 0
926# endif
zeertzjqf6272552024-03-17 10:01:47 +0100927 || wlv->win_attr != 0))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100928 {
929 int rightmost_vcol = 0;
930 int i;
931
932 if (wp->w_p_cuc)
933 rightmost_vcol = wp->w_virtcol;
934 if (wlv->draw_color_col)
935 // determine rightmost colorcolumn to possibly draw
936 for (i = 0; wlv->color_cols[i] >= 0; ++i)
937 if (rightmost_vcol < wlv->color_cols[i])
938 rightmost_vcol = wlv->color_cols[i];
939
zeertzjqf6272552024-03-17 10:01:47 +0100940 while (
941# ifdef FEAT_RIGHTLEFT
942 wp->w_p_rl ? (wlv->col >= 0) :
943# endif
944 (wlv->col < wp->w_width))
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100945 {
946 ScreenLines[wlv->off] = ' ';
947 if (enc_utf8)
948 ScreenLinesUC[wlv->off] = 0;
zeertzjqf6272552024-03-17 10:01:47 +0100949
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100950 if (wlv->draw_color_col)
951 wlv->draw_color_col = advance_color_col(
952 VCOL_HLC, &wlv->color_cols);
953
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000954 int attr = wlv->win_attr;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000955# ifdef LINE_ATTR
zeertzjq9352c282024-03-14 18:16:56 +0100956 if (wlv->line_attr != 0)
957 attr = hl_combine_attr(attr, wlv->line_attr);
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000958# endif
zeertzjq9352c282024-03-14 18:16:56 +0100959 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
960 && wlv->lnum != wp->w_cursor.lnum)
961 attr = hl_combine_attr(attr, HL_ATTR(HLF_CUC));
962 else if (wlv->draw_color_col && VCOL_HLC == *wlv->color_cols)
963 attr = hl_combine_attr(attr, HL_ATTR(HLF_MC));
zeertzjqf6272552024-03-17 10:01:47 +0100964 ScreenAttrs[wlv->off] = attr;
965 ScreenCols[wlv->off] = wlv->vcol;
966# ifdef FEAT_RIGHTLEFT
967 if (wp->w_p_rl)
968 {
969 --wlv->off;
970 --wlv->col;
971 }
972 else
973# endif
974 {
975 ++wlv->off;
976 ++wlv->col;
977 }
zeertzjqdeb22042024-03-17 19:44:30 +0100978 ++wlv->vcol;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100979
zeertzjqdeb22042024-03-17 19:44:30 +0100980 if (VCOL_HLC > rightmost_vcol
Bram Moolenaar45e4eea2022-12-01 18:38:02 +0000981# ifdef LINE_ATTR
982 && wlv->line_attr == 0
983# endif
984 && wlv->win_attr == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100985 break;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100986 }
987 }
988#endif
989
zeertzjqd0c1b772024-03-16 15:03:33 +0100990 // Set increasing virtual columns in ScreenCols[] to set correct curswant
991 // (or "coladd" for 'virtualedit') when clicking after end of line.
992 wlv->screen_line_flags |= SLF_INC_VCOL;
993 wlv_screen_line(wp, wlv, TRUE);
994 wlv->screen_line_flags &= ~SLF_INC_VCOL;
Bram Moolenaar4d91d342022-08-06 13:48:20 +0100995 ++wlv->row;
996 ++wlv->screen_row;
997}
998#undef VCOL_HLC
999
1000/*
1001 * Start a screen line at column zero.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001002 * When "save_extra" is TRUE save and reset n_extra, p_extra, etc.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001003 */
1004 static void
Bram Moolenaar1306b362022-08-06 15:59:06 +01001005win_line_start(win_T *wp UNUSED, winlinevars_T *wlv, int save_extra)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001006{
1007 wlv->col = 0;
1008 wlv->off = (unsigned)(current_ScreenLine - ScreenLines);
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001009#ifdef FEAT_LINEBREAK
1010 wlv->need_lbr = FALSE;
1011#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001012
1013#ifdef FEAT_RIGHTLEFT
1014 if (wp->w_p_rl)
1015 {
1016 // Rightleft window: process the text in the normal direction, but put
1017 // it in current_ScreenLine[] from right to left. Start at the
1018 // rightmost column of the window.
1019 wlv->col = wp->w_width - 1;
1020 wlv->off += wlv->col;
1021 wlv->screen_line_flags |= SLF_RIGHTLEFT;
1022 }
1023#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001024 if (save_extra)
1025 {
1026 // reset the drawing state for the start of a wrapped line
1027 wlv->draw_state = WL_START;
1028 wlv->saved_n_extra = wlv->n_extra;
1029 wlv->saved_p_extra = wlv->p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001030 vim_free(wlv->saved_p_extra_free);
1031 wlv->saved_p_extra_free = wlv->p_extra_free;
1032 wlv->p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001033 wlv->saved_extra_attr = wlv->extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001034 wlv->saved_n_attr_skip = wlv->n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001035 wlv->saved_extra_for_textprop = wlv->extra_for_textprop;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001036 wlv->saved_c_extra = wlv->c_extra;
1037 wlv->saved_c_final = wlv->c_final;
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02001038#ifdef FEAT_LINEBREAK
1039 wlv->need_lbr = TRUE;
1040#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001041#ifdef FEAT_SYN_HL
1042 if (!(wlv->cul_screenline
1043# ifdef FEAT_DIFF
1044 && wlv->diff_hlf == (hlf_T)0
1045# endif
1046 ))
1047 wlv->saved_char_attr = wlv->char_attr;
1048 else
1049#endif
1050 wlv->saved_char_attr = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001051
1052 // these are not used until restored in win_line_continue()
Bram Moolenaar1306b362022-08-06 15:59:06 +01001053 wlv->n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001054 wlv->n_attr_skip = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01001055 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001056}
1057
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001058/*
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001059 * Called when wlv->draw_state is set to WL_LINE.
1060 */
1061 static void
1062win_line_continue(winlinevars_T *wlv)
1063{
1064 if (wlv->saved_n_extra > 0)
1065 {
1066 // Continue item from end of wrapped line.
1067 wlv->n_extra = wlv->saved_n_extra;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001068 wlv->saved_n_extra = 0;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001069 wlv->c_extra = wlv->saved_c_extra;
1070 wlv->c_final = wlv->saved_c_final;
1071 wlv->p_extra = wlv->saved_p_extra;
zeertzjq58e1e012023-06-04 18:46:28 +01001072 vim_free(wlv->p_extra_free);
1073 wlv->p_extra_free = wlv->saved_p_extra_free;
1074 wlv->saved_p_extra_free = NULL;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001075 wlv->extra_attr = wlv->saved_extra_attr;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00001076 wlv->n_attr_skip = wlv->saved_n_attr_skip;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00001077 wlv->extra_for_textprop = wlv->saved_extra_for_textprop;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001078 wlv->char_attr = wlv->saved_char_attr;
1079 }
1080 else
1081 wlv->char_attr = wlv->win_attr;
1082}
1083
zeertzjqb7acea12022-12-12 13:20:43 +00001084#ifdef FEAT_SYN_HL
1085 static void
1086apply_cursorline_highlight(
1087 winlinevars_T *wlv,
1088 int sign_present UNUSED)
1089{
1090 wlv->cul_attr = HL_ATTR(HLF_CUL);
1091# ifdef FEAT_SIGNS
1092 // Combine the 'cursorline' and sign highlighting, depending on
1093 // the sign priority.
1094 if (sign_present && wlv->sattr.sat_linehl > 0)
1095 {
1096 if (wlv->sattr.sat_priority >= 100)
1097 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1098 else
1099 wlv->line_attr = hl_combine_attr(wlv->line_attr, wlv->cul_attr);
1100 }
1101 else
1102# endif
1103# if defined(FEAT_QUICKFIX)
1104 // let the line attribute overrule 'cursorline', otherwise
1105 // it disappears when both have background set;
1106 // 'cursorline' can use underline or bold to make it show
1107 wlv->line_attr = hl_combine_attr(wlv->cul_attr, wlv->line_attr);
1108# else
1109 wlv->line_attr = wlv->cul_attr;
1110# endif
1111}
1112#endif
1113
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001114/*
Luuk van Baal30805a12023-05-27 22:22:10 +01001115 * Display line "lnum" of window "wp" on the screen.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001116 * Start at row "startrow", stop when "endrow" is reached.
zeertzjqebfd8562024-02-06 10:59:03 +01001117 * When only updating the number column, "number_only" is set to the height of
1118 * the line, otherwise it is set to 0.
Luuk van Baal30805a12023-05-27 22:22:10 +01001119 * "spv" is used to store information for spell checking, kept between
1120 * sequential calls for the same window.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001121 * wp->w_virtcol needs to be valid.
1122 *
1123 * Return the number of last row the line occupies.
1124 */
1125 int
1126win_line(
1127 win_T *wp,
1128 linenr_T lnum,
1129 int startrow,
1130 int endrow,
Luuk van Baal30805a12023-05-27 22:22:10 +01001131 int number_only,
1132 spellvars_T *spv UNUSED)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001133{
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001134 winlinevars_T wlv; // variables passed between functions
1135
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001136 int c = 0; // init for GCC
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001137 long vcol_prev = -1; // "wlv.vcol" of previous character
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001138 char_u *line; // current line
1139 char_u *ptr; // current position in "line"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001140
Bram Moolenaar1306b362022-08-06 15:59:06 +01001141#ifdef FEAT_PROP_POPUP
1142 char_u *p_extra_free2 = NULL; // another p_extra to be freed
1143#endif
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001144#if defined(FEAT_LINEBREAK) && defined(FEAT_PROP_POPUP)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00001145 int in_linebreak = FALSE; // n_extra set for showing linebreak
1146#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01001147 int lcs_eol_one = wp->w_lcs_chars.eol; // eol until it's been used
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00001148 int lcs_prec_todo = wp->w_lcs_chars.prec;
1149 // prec until it's been used
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001150
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001151 int n_attr = 0; // chars with special attr
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001152 int saved_attr2 = 0; // char_attr saved for n_attr
1153 int n_attr3 = 0; // chars with overruling special attr
1154 int saved_attr3 = 0; // char_attr saved for n_attr3
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001155
zeertzjqb557f482023-08-22 22:07:34 +02001156 int skip_cells = 0; // nr of cells to skip for w_leftcol or
1157 // w_skipcol or concealing
1158 int skipped_cells = 0; // nr of skipped cells for virtual text
1159 // to be added to wlv.vcol later
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001160 int fromcol_prev = -2; // start of inverting after cursor
1161 int noinvcur = FALSE; // don't invert the cursor
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001162 int lnum_in_visual_area = FALSE;
1163 pos_T pos;
1164 long v;
1165
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001166 int attr_pri = FALSE; // char_attr has priority
1167 int area_highlighting = FALSE; // Visual or incsearch highlighting
1168 // in this line
1169 int vi_attr = 0; // attributes for Visual and incsearch
1170 // highlighting
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001171 int area_attr = 0; // attributes desired by highlighting
1172 int search_attr = 0; // attributes desired by 'hlsearch'
1173#ifdef FEAT_SYN_HL
1174 int vcol_save_attr = 0; // saved attr for 'cursorcolumn'
1175 int syntax_attr = 0; // attributes desired by syntax
Bram Moolenaar9115c612019-10-16 16:57:06 +02001176 int prev_syntax_col = -1; // column of prev_syntax_attr
1177 int prev_syntax_attr = 0; // syntax_attr at prev_syntax_col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001178 int has_syntax = FALSE; // this buffer has syntax highl.
1179 int save_did_emsg;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001180#endif
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001181#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00001182 int did_line = FALSE; // set to TRUE when line text done
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001183 int text_prop_count;
zeertzjq4e26a9a2023-12-03 17:50:47 +01001184 int last_textprop_text_idx = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001185 int text_prop_next = 0; // next text property to use
1186 textprop_T *text_props = NULL;
1187 int *text_prop_idxs = NULL;
1188 int text_props_active = 0;
1189 proptype_T *text_prop_type = NULL;
1190 int text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01001191 int text_prop_attr_comb = 0; // text_prop_attr combined with
1192 // syntax_attr
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001193 int text_prop_id = 0; // active property ID
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01001194 int text_prop_flags = 0;
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01001195 int text_prop_above = FALSE; // first doing virtual text above
Bram Moolenaarb7963df2022-07-31 17:12:43 +01001196 int text_prop_follows = FALSE; // another text prop to display
Bram Moolenaare38fc862022-08-11 17:24:50 +01001197 int saved_search_attr = 0; // search_attr to be used when n_extra
1198 // goes to zero
Bram Moolenaar6eda17d2022-09-12 19:25:11 +01001199 int saved_area_attr = 0; // idem for area_attr
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00001200 int reset_extra_attr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001201#endif
1202#ifdef FEAT_SPELL
Bram Moolenaarae49aa82022-02-25 21:05:36 +00001203 int can_spell = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001204# define SPWORDLEN 150
1205 char_u nextline[SPWORDLEN * 2];// text with start of the next line
1206 int nextlinecol = 0; // column where nextline[] starts
1207 int nextline_idx = 0; // index in nextline[] where next line
1208 // starts
1209 int spell_attr = 0; // attributes desired by spelling
1210 int word_end = 0; // last byte with same spell_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001211 int cur_checked_col = 0; // checked column for current line
1212#endif
1213 int extra_check = 0; // has extra highlighting
1214 int multi_attr = 0; // attributes desired by multibyte
1215 int mb_l = 1; // multi-byte byte length
1216 int mb_c = 0; // decoded multi-byte character
1217 int mb_utf8 = FALSE; // screen char is UTF-8 char
1218 int u8cc[MAX_MCO]; // composing UTF-8 chars
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001219#ifdef FEAT_DIFF
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001220 int change_start = MAXCOL; // first col of changed area
1221 int change_end = -1; // last col of changed area
1222#endif
1223 colnr_T trailcol = MAXCOL; // start of trailing spaces
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001224 colnr_T leadcol = 0; // start of leading spaces
zeertzjqf14b8ba2021-09-10 16:58:30 +02001225 int in_multispace = FALSE; // in multiple consecutive spaces
1226 int multispace_pos = 0; // position in lcs-multispace string
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001227#ifdef LINE_ATTR
Bram Moolenaarbf915842022-08-06 22:38:02 +01001228 int line_attr_save = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001229#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001230 int sign_present = FALSE;
James McCoya80aad72021-12-22 19:45:28 +00001231 int num_attr = 0; // attribute for the number column
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001232#ifdef FEAT_ARABIC
1233 int prev_c = 0; // previous Arabic character
1234 int prev_c1 = 0; // first composing char for prev_c
1235#endif
1236#if defined(LINE_ATTR)
1237 int did_line_attr = 0;
1238#endif
1239#ifdef FEAT_TERMINAL
1240 int get_term_attr = FALSE;
1241#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001242
Martin Tournoijba43e762022-10-13 22:12:15 +01001243#if defined(FEAT_SYN_HL) || defined(FEAT_DIFF)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001244 // margin columns for the screen line, needed for when 'cursorlineopt'
1245 // contains "screenline"
1246 int left_curline_col = 0;
1247 int right_curline_col = 0;
1248#endif
1249
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001250#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
1251 int feedback_col = 0;
1252 int feedback_old_attr = -1;
1253#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001254
1255#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
1256 int match_conc = 0; // cchar for match functions
Martin Tournoijba43e762022-10-13 22:12:15 +01001257#endif
1258#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA) || defined(FEAT_LINEBREAK)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00001259 int on_last_col = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001260#endif
1261#ifdef FEAT_CONCEAL
1262 int syntax_flags = 0;
1263 int syntax_seqnr = 0;
1264 int prev_syntax_id = 0;
1265 int conceal_attr = HL_ATTR(HLF_CONCEAL);
1266 int is_concealing = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001267 int did_wcol = FALSE;
1268 int old_boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001269# define VCOL_HLC (wlv.vcol - wlv.vcol_off_co - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001270# define FIX_FOR_BOGUSCOLS \
1271 { \
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001272 wlv.n_extra += wlv.vcol_off_co; \
1273 wlv.vcol -= wlv.vcol_off_co; \
1274 wlv.vcol_off_co = 0; \
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001275 wlv.col -= wlv.boguscols; \
1276 old_boguscols = wlv.boguscols; \
1277 wlv.boguscols = 0; \
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001278 }
1279#else
Bram Moolenaarf53e0652023-02-19 14:16:02 +00001280# define VCOL_HLC (wlv.vcol - wlv.vcol_off_tp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001281#endif
1282
1283 if (startrow > endrow) // past the end already!
1284 return startrow;
1285
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001286 CLEAR_FIELD(wlv);
1287
1288 wlv.lnum = lnum;
1289 wlv.startrow = startrow;
1290 wlv.row = startrow;
1291 wlv.screen_row = wlv.row + W_WINROW(wp);
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001292 wlv.fromcol = -10;
1293 wlv.tocol = MAXCOL;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001294#ifdef FEAT_LINEBREAK
1295 wlv.vcol_sbr = -1;
1296#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001297
zeertzjqebfd8562024-02-06 10:59:03 +01001298 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001299 {
1300 // To speed up the loop below, set extra_check when there is linebreak,
1301 // trailing white space and/or syntax processing to be done.
1302#ifdef FEAT_LINEBREAK
1303 extra_check = wp->w_p_lbr;
1304#endif
1305#ifdef FEAT_SYN_HL
1306 if (syntax_present(wp) && !wp->w_s->b_syn_error
1307# ifdef SYN_TIME_LIMIT
1308 && !wp->w_s->b_syn_slow
1309# endif
1310 )
1311 {
1312 // Prepare for syntax highlighting in this line. When there is an
1313 // error, stop syntax highlighting.
1314 save_did_emsg = did_emsg;
1315 did_emsg = FALSE;
1316 syntax_start(wp, lnum);
1317 if (did_emsg)
1318 wp->w_s->b_syn_error = TRUE;
1319 else
1320 {
1321 did_emsg = save_did_emsg;
1322#ifdef SYN_TIME_LIMIT
1323 if (!wp->w_s->b_syn_slow)
1324#endif
1325 {
1326 has_syntax = TRUE;
1327 extra_check = TRUE;
1328 }
1329 }
1330 }
1331
1332 // Check for columns to display for 'colorcolumn'.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001333 wlv.color_cols = wp->w_p_cc_cols;
1334 if (wlv.color_cols != NULL)
1335 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001336#endif
1337
1338#ifdef FEAT_TERMINAL
1339 if (term_show_buffer(wp->w_buffer))
1340 {
1341 extra_check = TRUE;
1342 get_term_attr = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001343 wlv.win_attr = term_get_attr(wp, lnum, -1);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001344 }
1345#endif
1346
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001347 // handle Visual active in this window
1348 if (VIsual_active && wp->w_buffer == curwin->w_buffer)
1349 {
Bram Moolenaar14285cb2020-03-27 20:58:37 +01001350 pos_T *top, *bot;
1351
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001352 if (LTOREQ_POS(curwin->w_cursor, VIsual))
1353 {
1354 // Visual is after curwin->w_cursor
1355 top = &curwin->w_cursor;
1356 bot = &VIsual;
1357 }
1358 else
1359 {
1360 // Visual is before curwin->w_cursor
1361 top = &VIsual;
1362 bot = &curwin->w_cursor;
1363 }
1364 lnum_in_visual_area = (lnum >= top->lnum && lnum <= bot->lnum);
1365 if (VIsual_mode == Ctrl_V)
1366 {
1367 // block mode
1368 if (lnum_in_visual_area)
1369 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001370 wlv.fromcol = wp->w_old_cursor_fcol;
1371 wlv.tocol = wp->w_old_cursor_lcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001372 }
1373 }
1374 else
1375 {
1376 // non-block mode
1377 if (lnum > top->lnum && lnum <= bot->lnum)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001378 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001379 else if (lnum == top->lnum)
1380 {
1381 if (VIsual_mode == 'V') // linewise
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001382 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001383 else
1384 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001385 getvvcol(wp, top, (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001386 if (gchar_pos(top) == NUL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001387 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001388 }
1389 }
1390 if (VIsual_mode != 'V' && lnum == bot->lnum)
1391 {
1392 if (*p_sel == 'e' && bot->col == 0 && bot->coladd == 0)
1393 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001394 wlv.fromcol = -10;
1395 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001396 }
1397 else if (bot->col == MAXCOL)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001398 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001399 else
1400 {
1401 pos = *bot;
1402 if (*p_sel == 'e')
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001403 getvvcol(wp, &pos, (colnr_T *)&wlv.tocol,
1404 NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001405 else
1406 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001407 getvvcol(wp, &pos, NULL, NULL,
1408 (colnr_T *)&wlv.tocol);
1409 ++wlv.tocol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001410 }
1411 }
1412 }
1413 }
1414
1415 // Check if the character under the cursor should not be inverted
Bram Moolenaar6656c2e2019-10-24 15:00:04 +02001416 if (!highlight_match && lnum == curwin->w_cursor.lnum
1417 && wp == curwin
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001418#ifdef FEAT_GUI
1419 && !gui.in_use
1420#endif
1421 )
1422 noinvcur = TRUE;
1423
1424 // if inverting in this line set area_highlighting
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001425 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001426 {
1427 area_highlighting = TRUE;
1428 vi_attr = HL_ATTR(HLF_V);
1429#if defined(FEAT_CLIPBOARD) && defined(FEAT_X11)
1430 if ((clip_star.available && !clip_star.owned
1431 && clip_isautosel_star())
1432 || (clip_plus.available && !clip_plus.owned
1433 && clip_isautosel_plus()))
1434 vi_attr = HL_ATTR(HLF_VNC);
1435#endif
1436 }
1437 }
1438
1439 // handle 'incsearch' and ":s///c" highlighting
1440 else if (highlight_match
1441 && wp == curwin
1442 && lnum >= curwin->w_cursor.lnum
1443 && lnum <= curwin->w_cursor.lnum + search_match_lines)
1444 {
1445 if (lnum == curwin->w_cursor.lnum)
1446 getvcol(curwin, &(curwin->w_cursor),
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001447 (colnr_T *)&wlv.fromcol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001448 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001449 wlv.fromcol = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001450 if (lnum == curwin->w_cursor.lnum + search_match_lines)
1451 {
1452 pos.lnum = lnum;
1453 pos.col = search_match_endcol;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001454 getvcol(curwin, &pos, (colnr_T *)&wlv.tocol, NULL, NULL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001455 }
1456 else
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001457 wlv.tocol = MAXCOL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001458 // do at least one character; happens when past end of line
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001459 if (wlv.fromcol == wlv.tocol && search_match_endcol)
1460 wlv.tocol = wlv.fromcol + 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001461 area_highlighting = TRUE;
1462 vi_attr = HL_ATTR(HLF_I);
1463 }
1464 }
1465
1466#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01001467 wlv.filler_lines = diff_check(wp, lnum);
1468 if (wlv.filler_lines < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001469 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001470 if (wlv.filler_lines == -1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001471 {
1472 if (diff_find_change(wp, lnum, &change_start, &change_end))
Bram Moolenaar1306b362022-08-06 15:59:06 +01001473 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001474 else if (change_start == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001475 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001476 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001477 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001478 }
1479 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01001480 wlv.diff_hlf = HLF_ADD; // added line
Bram Moolenaard7657e92022-09-20 18:59:30 +01001481 wlv.filler_lines = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001482 area_highlighting = TRUE;
1483 }
1484 if (lnum == wp->w_topline)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001485 wlv.filler_lines = wp->w_topfill;
1486 wlv.filler_todo = wlv.filler_lines;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001487#endif
1488
1489#ifdef FEAT_SIGNS
Bram Moolenaard7657e92022-09-20 18:59:30 +01001490 sign_present = buf_get_signattrs(wp, lnum, &wlv.sattr);
James McCoya80aad72021-12-22 19:45:28 +00001491 if (sign_present)
Bram Moolenaard7657e92022-09-20 18:59:30 +01001492 num_attr = wlv.sattr.sat_numhl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001493#endif
1494
1495#ifdef LINE_ATTR
1496# ifdef FEAT_SIGNS
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001497 // If this line has a sign with line highlighting set wlv.line_attr.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001498 if (sign_present)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001499 wlv.line_attr = wlv.sattr.sat_linehl;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001500# endif
1501# if defined(FEAT_QUICKFIX)
1502 // Highlight the current line in the quickfix window.
1503 if (bt_quickfix(wp->w_buffer) && qf_current_entry(wp) == lnum)
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001504 wlv.line_attr = HL_ATTR(HLF_QFL);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001505# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001506 if (wlv.line_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001507 area_highlighting = TRUE;
1508#endif
1509
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001510#ifdef FEAT_SPELL
zeertzjqebfd8562024-02-06 10:59:03 +01001511 if (spv->spv_has_spell && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001512 {
Luuk van Baal30805a12023-05-27 22:22:10 +01001513 // Prepare for spell checking.
1514 extra_check = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001515
Luuk van Baal30805a12023-05-27 22:22:10 +01001516 // When a word wrapped from the previous line the start of the
1517 // current line is valid.
1518 if (lnum == spv->spv_checked_lnum)
1519 cur_checked_col = spv->spv_checked_col;
Luuk van Baale84c7732023-05-31 18:57:36 +01001520 // Previous line was not spell checked, check for capital. This happens
1521 // for the first line in an updated region or after a closed fold.
1522 if (spv->spv_capcol_lnum == 0 && check_need_cap(wp, lnum, 0))
1523 spv->spv_cap_col = 0;
1524 else if (lnum != spv->spv_capcol_lnum)
Luuk van Baal30805a12023-05-27 22:22:10 +01001525 spv->spv_cap_col = -1;
1526 spv->spv_checked_lnum = 0;
1527
Luuk van Baal30805a12023-05-27 22:22:10 +01001528 // Get the start of the next line, so that words that wrap to the
1529 // next line are found too: "et<line-break>al.".
1530 // Trick: skip a few chars for C/shell/Vim comments
1531 nextline[SPWORDLEN] = NUL;
1532 if (lnum < wp->w_buffer->b_ml.ml_line_count)
Luuk van Baale84c7732023-05-31 18:57:36 +01001533 {
1534 line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
1535 spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
1536 }
1537 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1538
1539 // If current line is empty, check first word in next line for capital.
1540 ptr = skipwhite(line);
1541 if (*ptr == NUL)
1542 {
1543 spv->spv_cap_col = 0;
1544 spv->spv_capcol_lnum = lnum + 1;
1545 }
1546 // For checking first word with a capital skip white space.
1547 else if (spv->spv_cap_col == 0)
1548 spv->spv_cap_col = ptr - line;
1549
Luuk van Baal30805a12023-05-27 22:22:10 +01001550 // Copy the end of the current line into nextline[].
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001551 if (nextline[SPWORDLEN] == NUL)
1552 {
1553 // No next line or it is empty.
1554 nextlinecol = MAXCOL;
1555 nextline_idx = 0;
1556 }
1557 else
1558 {
zeertzjq94b7c322024-03-12 21:50:32 +01001559 v = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001560 if (v < SPWORDLEN)
1561 {
1562 // Short line, use it completely and append the start of the
1563 // next line.
1564 nextlinecol = 0;
1565 mch_memmove(nextline, line, (size_t)v);
1566 STRMOVE(nextline + v, nextline + SPWORDLEN);
1567 nextline_idx = v + 1;
1568 }
1569 else
1570 {
1571 // Long line, use only the last SPWORDLEN bytes.
1572 nextlinecol = v - SPWORDLEN;
1573 mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
1574 nextline_idx = SPWORDLEN + 1;
1575 }
1576 }
1577 }
1578#endif
1579
Luuk van Baale84c7732023-05-31 18:57:36 +01001580 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1581 ptr = line;
1582
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001583 if (wp->w_p_list)
1584 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01001585 if (wp->w_lcs_chars.space
zeertzjqf14b8ba2021-09-10 16:58:30 +02001586 || wp->w_lcs_chars.multispace != NULL
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001587 || wp->w_lcs_chars.leadmultispace != NULL
Bram Moolenaareed9d462021-02-15 20:38:25 +01001588 || wp->w_lcs_chars.trail
1589 || wp->w_lcs_chars.lead
1590 || wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001591 extra_check = TRUE;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001592
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001593 // find start of trailing whitespace
Bram Moolenaareed9d462021-02-15 20:38:25 +01001594 if (wp->w_lcs_chars.trail)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001595 {
zeertzjq94b7c322024-03-12 21:50:32 +01001596 trailcol = ml_get_buf_len(wp->w_buffer, lnum);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001597 while (trailcol > (colnr_T)0 && VIM_ISWHITE(ptr[trailcol - 1]))
1598 --trailcol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01001599 trailcol += (colnr_T)(ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001600 }
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001601 // find end of leading whitespace
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01001602 if (wp->w_lcs_chars.lead || wp->w_lcs_chars.leadmultispace != NULL)
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001603 {
1604 leadcol = 0;
1605 while (VIM_ISWHITE(ptr[leadcol]))
1606 ++leadcol;
1607 if (ptr[leadcol] == NUL)
1608 // in a line full of spaces all of them are treated as trailing
1609 leadcol = (colnr_T)0;
1610 else
1611 // keep track of the first column not filled with spaces
Bram Moolenaarb9081882022-07-09 04:56:24 +01001612 leadcol += (colnr_T)(ptr - line) + 1;
Bram Moolenaar91478ae2021-02-03 15:58:13 +01001613 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001614 }
1615
Bram Moolenaard7657e92022-09-20 18:59:30 +01001616 wlv.wcr_attr = get_wcr_attr(wp);
1617 if (wlv.wcr_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001618 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001619 wlv.win_attr = wlv.wcr_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001620 area_highlighting = TRUE;
1621 }
Bram Moolenaar34390282019-10-16 14:38:26 +02001622
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001623 // When w_skipcol is non-zero and there is virtual text above the actual
1624 // text, then this much of the virtual text is skipped.
1625 int skipcol_in_text_prop_above = 0;
1626
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01001627#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001628 if (WIN_IS_POPUP(wp))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001629 wlv.screen_line_flags |= SLF_POPUP;
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001630
1631 char_u *prop_start;
1632 text_prop_count = get_text_props(wp->w_buffer, lnum, &prop_start, FALSE);
1633 if (text_prop_count > 0)
1634 {
1635 // Make a copy of the properties, so that they are properly
1636 // aligned.
1637 text_props = ALLOC_MULT(textprop_T, text_prop_count);
1638 if (text_props != NULL)
1639 mch_memmove(text_props, prop_start,
1640 text_prop_count * sizeof(textprop_T));
1641
1642 // Allocate an array for the indexes.
1643 text_prop_idxs = ALLOC_MULT(int, text_prop_count);
1644 if (text_prop_idxs == NULL)
1645 VIM_CLEAR(text_props);
1646
1647 if (text_props != NULL)
1648 {
1649 area_highlighting = TRUE;
1650 extra_check = TRUE;
1651
zeertzjq4e26a9a2023-12-03 17:50:47 +01001652 /* Find the last text property that inserts text. */
1653 for (int i = 0; i < text_prop_count; ++i)
1654 if (text_props[i].tp_id < 0)
1655 last_textprop_text_idx = i;
1656
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001657 // Text props "above" move the line number down to where the text
1658 // is. Only count the ones that are visible, not those that are
1659 // skipped because of w_skipcol.
1660 int text_width = wp->w_width - win_col_off(wp);
1661 for (int i = text_prop_count - 1; i >= 0; --i)
1662 if (text_props[i].tp_flags & TP_FLAG_ALIGN_ABOVE)
1663 {
1664 if (lnum == wp->w_topline
1665 && wp->w_skipcol - skipcol_in_text_prop_above
1666 >= text_width)
1667 {
1668 // This virtual text above is skipped, remove it from
1669 // the array.
1670 skipcol_in_text_prop_above += text_width;
1671 for (int j = i + 1; j < text_prop_count; ++j)
1672 text_props[j - 1] = text_props[j];
1673 ++i;
1674 --text_prop_count;
1675 }
1676 else
1677 ++wlv.text_prop_above_count;
1678 }
1679 }
1680 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001681
zeertzjqebfd8562024-02-06 10:59:03 +01001682 if (number_only > 0)
Bram Moolenaara572b932023-02-19 14:34:37 +00001683 {
1684 // skip over rows only used for virtual text above
1685 wlv.row += wlv.text_prop_above_count;
1686 if (wlv.row > endrow)
1687 return wlv.row;
1688 wlv.screen_row += wlv.text_prop_above_count;
1689 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001690#endif
1691
zeertzjqce53e3e2023-09-01 18:49:30 +02001692#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1693 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001694 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001695 {
1696 chartabsize_T cts;
1697 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1698 (void)win_lbr_chartabsize(&cts, NULL);
1699 vcol_first_char = cts.cts_first_char;
1700 clear_chartabsize_arg(&cts);
1701 }
1702#endif
1703
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001704 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1705 // first character to be displayed.
1706 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001707 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 else
1709 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001710 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001711 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001712 char_u *prev_ptr = ptr;
1713 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001714 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001715 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001716
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001717 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001718 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001719 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720 {
zeertzjqb557f482023-08-22 22:07:34 +02001721 head = 0;
1722 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001723 cts.cts_vcol += charsize;
1724 prev_ptr = cts.cts_ptr;
1725 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001726 if (wp->w_p_list)
1727 {
1728 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1729 || (prev_ptr > line && prev_ptr[-1] == ' '));
1730 if (!in_multispace)
1731 multispace_pos = 0;
1732 else if (cts.cts_ptr >= line + leadcol
1733 && wp->w_lcs_chars.multispace != NULL)
1734 {
1735 ++multispace_pos;
1736 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1737 multispace_pos = 0;
1738 }
1739 else if (cts.cts_ptr < line + leadcol
1740 && wp->w_lcs_chars.leadmultispace != NULL)
1741 {
1742 ++multispace_pos;
1743 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1744 multispace_pos = 0;
1745 }
1746 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001747 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001748 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001749 ptr = cts.cts_ptr;
1750 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751
1752 // When:
1753 // - 'cuc' is set, or
1754 // - 'colorcolumn' is set, or
1755 // - 'virtualedit' is set, or
1756 // - the visual mode is active,
1757 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001758 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001759#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001760 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001761#endif
1762 virtual_active() ||
1763 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001764 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765
1766 // Handle a character that's not completely on the screen: Put ptr at
1767 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001768 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001770 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001771 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001772 }
zeertzjqb557f482023-08-22 22:07:34 +02001773 if (v > wlv.vcol)
1774 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001775
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 // Adjust for when the inverted text is before the screen,
1777 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001778 if (wlv.tocol <= wlv.vcol)
1779 wlv.fromcol = 0;
1780 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1781 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001782
1783#ifdef FEAT_LINEBREAK
1784 // When w_skipcol is non-zero, first line needs 'showbreak'
1785 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001786 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001787#endif
1788#ifdef FEAT_SPELL
1789 // When spell checking a word we need to figure out the start of the
1790 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001791 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001792 {
1793 int len;
1794 colnr_T linecol = (colnr_T)(ptr - line);
1795 hlf_T spell_hlf = HLF_COUNT;
1796
1797 pos = wp->w_cursor;
1798 wp->w_cursor.lnum = lnum;
1799 wp->w_cursor.col = linecol;
1800 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1801
1802 // spell_move_to() may call ml_get() and make "line" invalid
1803 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1804 ptr = line + linecol;
1805
1806 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1807 {
1808 // no bad word found at line start, don't check until end of a
1809 // word
1810 spell_hlf = HLF_COUNT;
1811 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1812 }
1813 else
1814 {
1815 // bad word found, use attributes until end of word
1816 word_end = wp->w_cursor.col + len + 1;
1817
1818 // Turn index into actual attributes.
1819 if (spell_hlf != HLF_COUNT)
1820 spell_attr = highlight_attr[spell_hlf];
1821 }
1822 wp->w_cursor = pos;
1823
1824# ifdef FEAT_SYN_HL
1825 // Need to restart syntax highlighting for this line.
1826 if (has_syntax)
1827 syntax_start(wp, lnum);
1828# endif
1829 }
1830#endif
1831 }
1832
1833 // Correct highlighting for cursor that can't be disabled.
1834 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001835 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001836 {
1837 if (noinvcur)
1838 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001839 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 {
1841 // highlighting starts at cursor, let it start just after the
1842 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001843 fromcol_prev = wlv.fromcol;
1844 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001845 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001846 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001847 // restart highlighting after the cursor
1848 fromcol_prev = wp->w_virtcol;
1849 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001850 if (wlv.fromcol >= wlv.tocol)
1851 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001852 }
1853
1854#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001855 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 {
1857 v = (long)(ptr - line);
1858 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1859 &line, &screen_search_hl,
1860 &search_attr);
1861 ptr = line + v; // "line" may have been updated
1862 }
1863#endif
1864
1865#ifdef FEAT_SYN_HL
1866 // Cursor line highlighting for 'cursorline' in the current window.
1867 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1868 {
1869 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001870 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001871 if (!(wp == curwin && VIsual_active)
1872 && wp->w_p_culopt_flags != CULOPT_NBR)
1873 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001874 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1876
zeertzjqb7acea12022-12-12 13:20:43 +00001877 // Only apply CursorLine highlight here when "screenline" is not
1878 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001879 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001880 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001881 else
1882 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001883 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001884 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1885 }
1886 area_highlighting = TRUE;
1887 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 }
1889#endif
1890
Bram Moolenaar1306b362022-08-06 15:59:06 +01001891 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892
1893 // Repeat for the whole displayed line.
1894 for (;;)
1895 {
1896#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001897 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001898#endif
1899#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001900 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001901#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001902
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001903 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001904 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001906#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001907 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001908 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001909 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001910 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001911 }
1912#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001913 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001914 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001915 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001916 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001917 {
1918 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919 wlv.n_extra = 1;
1920 wlv.c_extra = cmdwin_type;
1921 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001922 wlv.char_attr =
1923 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001924 }
1925 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001926#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001927 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001929 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001930 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001931 }
1932#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001933#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001934 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001936 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001937 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001938 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001939 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001940 }
1941#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001942 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001943 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001944 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001945 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001946 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 }
zeertzjqebfd8562024-02-06 10:59:03 +01001948
1949 // When only displaying the (relative) line number and that's done,
1950 // stop here.
1951 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1952 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001953 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001954 // Need to update more screen lines if:
1955 // - LineNrAbove or LineNrBelow is used, or
1956 // - still drawing filler lines.
1957 if ((wlv.row + 1 - wlv.startrow < number_only
1958 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1959#ifdef FEAT_DIFF
1960 || wlv.filler_todo > 0
1961#endif
1962 )
1963 {
1964 ++wlv.row;
1965 ++wlv.screen_row;
1966 if (wlv.row == endrow)
1967 break;
1968#ifdef FEAT_DIFF
1969 --wlv.filler_todo;
1970 if (wlv.filler_todo == 0 && wp->w_botfill)
1971 break;
1972#endif
1973 win_line_start(wp, &wlv, TRUE);
1974 continue;
1975 }
1976 else
1977 break;
1978 }
1979
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001980#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001981 // Check if 'breakindent' applies and show it.
1982 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1983 if (wlv.n_extra == 0)
1984 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001985#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001986#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001987 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001988 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001989 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001990 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001991 }
1992#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001993 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001994 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001995 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001996 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001997 }
1998 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001999
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002000#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002001 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002002 && wlv.vcol >= left_curline_col
2003 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002004 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002005#endif
2006
2007 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01002008 if (dollar_vcol >= 0 && wp == curwin
2009 && lnum == wp->w_cursor.lnum
2010 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002011 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002012 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002013 // Pretend we have finished updating the window. Except when
2014 // 'cursorcolumn' is set.
2015#ifdef FEAT_SYN_HL
2016 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002017 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002018 else
2019#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002020 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002021 break;
2022 }
2023
Bram Moolenaar1306b362022-08-06 15:59:06 +01002024 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002026#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002027 if (text_props != NULL)
2028 {
2029 int pi;
2030 int bcol = (int)(ptr - line);
2031
Bram Moolenaar1306b362022-08-06 15:59:06 +01002032 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002033# ifdef FEAT_LINEBREAK
2034 && !in_linebreak
2035# endif
2036 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002037 --bcol; // still working on the previous char, e.g. Tab
2038
2039 // Check if any active property ends.
2040 for (pi = 0; pi < text_props_active; ++pi)
2041 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002042 int tpi = text_prop_idxs[pi];
2043 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002044
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002045 // An inline property ends when after the start column plus
2046 // length. An "above" property ends when used and n_extra
2047 // is zero.
2048 if ((tp->tp_col != MAXCOL
2049 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002050 {
2051 if (pi + 1 < text_props_active)
2052 mch_memmove(text_prop_idxs + pi,
2053 text_prop_idxs + pi + 1,
2054 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002055 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002056 --text_props_active;
2057 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002058# ifdef FEAT_LINEBREAK
2059 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002060 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002061 syntax_attr = 0;
2062# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002063 }
2064 }
2065
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002066# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002067 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002068 // not on the next char yet, don't start another prop
2069 --bcol;
2070# endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002071 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002072
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002073 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002074 // With 'nowrap' and not in the first screen line only "below"
2075 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002076 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002077 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002078 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002079 && (wp->w_p_wrap
2080 || wlv.row == startrow
2081 || (text_props[text_prop_next].tp_flags
2082 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002083 || (bcol == 0
2084 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002085 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002086 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002087 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002088 if (text_props[text_prop_next].tp_col == MAXCOL
2089 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002090 + text_props[text_prop_next].tp_len)
2091 text_prop_idxs[text_props_active++] = text_prop_next;
2092 ++text_prop_next;
2093 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002094
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002095 if (wlv.n_extra == 0 ||
2096 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002097 && !(text_prop_type != NULL &&
2098 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002099 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002100 {
2101 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002102 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002103 text_prop_flags = 0;
2104 text_prop_type = NULL;
2105 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002106 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002107 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002108 if (text_props_active > 0 && wlv.n_extra == 0
2109 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002110 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002111 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002112 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002113 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002114
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002115 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002116 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002117
2118 // Sort the properties on priority and/or starting last.
2119 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002120 sort_text_props(wp->w_buffer, text_props,
2121 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002122
2123 for (pi = 0; pi < text_props_active; ++pi)
2124 {
2125 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002126 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002127 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002128 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002129
Bram Moolenaarcd105412022-10-10 19:50:42 +01002130 // Only use a text property that can be displayed.
2131 // Skip "after" properties when wrap is off and at the
2132 // end of the window.
2133 if (pt != NULL
2134 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2135 && tp->tp_id != -MAXCOL
2136 && !(tp->tp_id < 0
2137 && !wp->w_p_wrap
2138 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2139 | TP_FLAG_ALIGN_ABOVE
2140 | TP_FLAG_ALIGN_BELOW)) == 0
2141 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002142 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002143 if (tp->tp_col == MAXCOL
2144 && *ptr == NUL
2145 && ((wp->w_p_list && lcs_eol_one > 0
2146 && (tp->tp_flags
2147 & TP_FLAG_ALIGN_ABOVE) == 0)
2148 || (ptr == line
2149 && !did_line
2150 && (tp->tp_flags
2151 & TP_FLAG_ALIGN_BELOW))))
2152 {
2153 // skip this prop, first display the '$' after
2154 // the line or display an empty line
2155 text_prop_follows = TRUE;
2156 if (used_tpi < 0)
2157 display_text_first = TRUE;
2158 continue;
2159 }
2160
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002161 if (pt->pt_hl_id > 0)
2162 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002163 text_prop_type = pt;
2164 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002165 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002166 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2167 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002168 text_prop_flags = pt->pt_flags;
2169 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002170 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002171 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002172 }
2173 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002174 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002175 && -text_prop_id
2176 <= wp->w_buffer->b_textprop_text.ga_len)
2177 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002178 textprop_T *tp = &text_props[used_tpi];
2179 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002180 ->b_textprop_text.ga_data)[
2181 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002182 int above = (tp->tp_flags
2183 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002184 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002185
2186 // reset the ID in the copy to avoid it being used
2187 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002188 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002190 if (p != NULL)
2191 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002192 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002193 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002194 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002195 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002196 int wrap = tp->tp_col < MAXCOL
2197 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002198 int padding = tp->tp_col == MAXCOL
2199 && tp->tp_len > 1
2200 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002201
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002202 // Insert virtual text before the current
2203 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002204 wlv.p_extra = p;
2205 wlv.c_extra = NUL;
2206 wlv.c_final = NUL;
2207 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002208 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002209 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002210 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2211 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002212 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002213 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002214 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002215 if (*ptr == NUL)
2216 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002217 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002218# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002219 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002220 {
2221 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002222 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002223 wlv.need_showbreak = FALSE;
2224 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002225 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002226# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002227 if ((right || above || below || !wrap
2228 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002229 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002230 char_u *prev_p_extra = wlv.p_extra;
2231 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002232
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002233 // Take care of padding, right-align and
2234 // truncation.
2235 // Shared with win_lbr_chartabsize(), must do
2236 // exactly the same.
2237 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002238 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002239# ifdef FEAT_RIGHTLEFT
2240 wp->w_p_rl
2241 ? wp->w_width - wlv.col - 1
2242 :
2243# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002244 wlv.col,
2245 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002246 &n_attr, &wlv.n_attr_skip,
2247 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002248 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002249 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002250 // wlv.p_extra was allocated
2251 vim_free(p_extra_free2);
2252 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002253 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002254
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002255 if (above)
2256 wlv.vcol_off_tp = wlv.n_extra;
2257
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002258 if (lcs_eol_one < 0
2259 && wp->w_p_wrap
2260 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002261 + wlv.n_extra - 2 > wp->w_width)
2262 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002263 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002264
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002265 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002266 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002267 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002268 {
2269 draw_screen_line(wp, &wlv);
2270
2271 // When line got too long for screen break
2272 // here.
2273 if (wlv.row == endrow)
2274 {
2275 ++wlv.row;
2276 break;
2277 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002278 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002279 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002280 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002281 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002282 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002283
Bram Moolenaarcd105412022-10-10 19:50:42 +01002284 // If the text didn't reach until the first window
2285 // column we need to skip cells.
2286 if (skip_cells > 0)
2287 {
2288 if (wlv.n_extra > skip_cells)
2289 {
2290 wlv.n_extra -= skip_cells;
2291 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002292 wlv.n_attr_skip -= skip_cells;
2293 if (wlv.n_attr_skip < 0)
2294 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002295 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002296 skip_cells = 0;
2297 }
2298 else
2299 {
2300 // the whole text is left of the window, drop
2301 // it and advance to the next one
2302 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002303 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002304 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002305 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002306 bail_out = TRUE;
2307 }
2308 }
2309
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002310 // If another text prop follows the condition below at
2311 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002312 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002313 // must wrap anyway.
2314 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002315 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002316 && (wp->w_p_wrap
2317 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002318 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002319
2320 if (bail_out)
2321 // starting a new line for "below"
2322 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002323 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002324 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002325 else if (text_prop_next < text_prop_count
2326 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002327 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2328 || (!wp->w_p_wrap
2329 && wlv.col == wp->w_width - 1
2330 && (text_props[text_prop_next].tp_flags
2331 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002332 // When at last-but-one character and a text property
2333 // follows after it, we may need to flush the line after
2334 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002335 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002336 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002337 }
zeertzjq6e940d92023-08-17 23:21:40 +02002338
2339 if (wlv.start_extra_for_textprop)
2340 {
2341 wlv.start_extra_for_textprop = FALSE;
2342 // restore search_attr and area_attr when n_extra
2343 // is down to zero
2344 saved_search_attr = search_attr;
2345 saved_area_attr = area_attr;
2346 search_attr = 0;
2347 area_attr = 0;
2348 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002349#endif
2350
zeertzjq6e940d92023-08-17 23:21:40 +02002351 int *area_attr_p =
2352#ifdef FEAT_PROP_POPUP
2353 wlv.extra_for_textprop ? &saved_area_attr :
2354#endif
2355 &area_attr;
2356
2357 // handle Visual or match highlighting in this line
2358 if (wlv.vcol == wlv.fromcol
2359 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2360 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2361 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2362 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2363 || ((int)vcol_prev == fromcol_prev
2364 && vcol_prev < wlv.vcol // not at margin
2365 && wlv.vcol < wlv.tocol))
2366 *area_attr_p = vi_attr; // start highlighting
2367 else if (*area_attr_p != 0
2368 && (wlv.vcol == wlv.tocol
2369 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2370 *area_attr_p = 0; // stop highlighting
2371
zeertzjqe500ae82023-08-17 22:35:26 +02002372#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002373 if (wlv.n_extra == 0)
2374 {
2375 // Check for start/end of 'hlsearch' and other matches.
2376 // After end, check for start/end of next match.
2377 // When another match, have to check for start again.
2378 v = (long)(ptr - line);
2379 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2380 &screen_search_hl, &has_match_conc,
2381 &match_conc, did_line_attr, lcs_eol_one,
2382 &on_last_col);
2383 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002384
2385 // Do not allow a conceal over EOL otherwise EOL will be missed
2386 // and bad things happen.
2387 if (*ptr == NUL)
2388 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002389 }
zeertzjqe500ae82023-08-17 22:35:26 +02002390#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002391
Bram Moolenaare38fc862022-08-11 17:24:50 +01002392#ifdef FEAT_DIFF
2393 if (wlv.diff_hlf != (hlf_T)0)
2394 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002395 // When there is extra text (e.g. virtual text) it gets the
2396 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002397 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2398 && wlv.n_extra == 0)
2399 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002400 if (wlv.diff_hlf == HLF_TXD
2401 && ((ptr - line > change_end && wlv.n_extra == 0)
2402 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002403 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002404 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002405 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2406 && wp->w_p_culopt_flags != CULOPT_NBR
2407 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2408 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002409 wlv.line_attr = hl_combine_attr(
2410 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002411 }
2412#endif
2413
Bram Moolenaara74fda62019-10-19 17:38:03 +02002414#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002415 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002416 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002417 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002418# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002419 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002420 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002421# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002422 // Get syntax attribute.
2423 if (has_syntax)
2424 {
2425 // Get the syntax attribute for the character. If there
2426 // is an error, disable syntax highlighting.
2427 save_did_emsg = did_emsg;
2428 did_emsg = FALSE;
2429
2430 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002431 if (v == prev_syntax_col)
2432 // at same column again
2433 syntax_attr = prev_syntax_attr;
2434 else
2435 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002436# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002437 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002438# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002439 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002440# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002441 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002442# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002443 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002444 prev_syntax_col = v;
2445 prev_syntax_attr = syntax_attr;
2446 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002447
Bram Moolenaar34390282019-10-16 14:38:26 +02002448 if (did_emsg)
2449 {
2450 wp->w_s->b_syn_error = TRUE;
2451 has_syntax = FALSE;
2452 syntax_attr = 0;
2453 }
2454 else
2455 did_emsg = save_did_emsg;
2456# ifdef SYN_TIME_LIMIT
2457 if (wp->w_s->b_syn_slow)
2458 has_syntax = FALSE;
2459# endif
2460
2461 // Need to get the line again, a multi-line regexp may
2462 // have made it invalid.
2463 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2464 ptr = line + v;
2465# ifdef FEAT_CONCEAL
2466 // no concealing past the end of the line, it interferes
2467 // with line highlighting
2468 if (*ptr == NUL)
2469 syntax_flags = 0;
2470 else
2471 syntax_flags = get_syntax_info(&syntax_seqnr);
2472# endif
2473 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002474 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002475# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002476 // Combine text property highlight into syntax highlight.
2477 if (text_prop_type != NULL)
2478 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002479 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002480 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2481 else
2482 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002483 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002484 }
2485# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002486#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002487
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002488 // Decide which of the highlight attributes to use.
2489 attr_pri = TRUE;
2490#ifdef LINE_ATTR
2491 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002492 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002493 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002494 if (!highlight_match)
2495 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002497# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002498 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002499# endif
2500 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002501 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002502 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002503 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002504# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002505 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002506# endif
2507 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002508 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002509 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2510 || wlv.vcol < wlv.fromcol
2511 || vcol_prev < fromcol_prev
2512 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002514 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002515 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002516# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002517 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002518# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002519 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002520# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002521 attr_pri = FALSE;
2522 }
2523#else
2524 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002525 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002527 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002528#endif
2529 else
2530 {
2531 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002534#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002535 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002536#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002537 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002538#ifdef FEAT_PROP_POPUP
2539 // override with text property highlight when "override" is TRUE
2540 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002541 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002542#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002543 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002544
2545 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002546 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002548 if (wlv.char_attr == 0)
2549 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002550 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002551 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002552 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002553
2554 // Get the next character to put on the screen.
2555
2556 // The "p_extra" points to the extra stuff that is inserted to
2557 // represent special characters (non-printable stuff) and other
2558 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002559 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002560 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2561 // "p_extra[n_extra]".
2562 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002565 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002566 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2568 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002569 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2570 if (enc_utf8 && utf_char2len(c) > 1)
2571 {
2572 mb_utf8 = TRUE;
2573 u8cc[0] = 0;
2574 c = 0xc0;
2575 }
2576 else
2577 mb_utf8 = FALSE;
2578 }
2579 else
2580 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002581 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002582 if (has_mbyte)
2583 {
2584 mb_c = c;
2585 if (enc_utf8)
2586 {
2587 // If the UTF-8 character is more than one byte:
2588 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002591 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002592 mb_l = 1;
2593 else if (mb_l > 1)
2594 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 mb_utf8 = TRUE;
2597 c = 0xc0;
2598 }
2599 }
2600 else
2601 {
2602 // if this is a DBCS character, put it in "mb_c"
2603 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002604 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002605 mb_l = 1;
2606 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002607 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002608 }
2609 if (mb_l == 0) // at the NUL at end-of-line
2610 mb_l = 1;
2611
2612 // If a double-width char doesn't fit display a '>' in the
2613 // last column.
2614 if ((
2615# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002616 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002618 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002619 && (*mb_char2cells)(mb_c) == 2)
2620 {
2621 c = '>';
2622 mb_c = c;
2623 mb_l = 1;
2624 mb_utf8 = FALSE;
2625 multi_attr = HL_ATTR(HLF_AT);
2626#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002627 if (wlv.cul_attr)
2628 multi_attr = hl_combine_attr(
2629 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002630#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002631 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002632
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002633 // put the pointer back to output the double-width
2634 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002635 ++wlv.n_extra;
2636 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637 }
2638 else
2639 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002640 wlv.n_extra -= mb_l - 1;
2641 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002642 }
2643 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002645 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002646 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002647#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002649 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002650 // Only restore search_attr and area_attr after "n_extra" in
2651 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002652 if (wlv.saved_n_extra <= 0)
2653 {
2654 if (search_attr == 0)
2655 search_attr = saved_search_attr;
2656 if (area_attr == 0 && *ptr != NUL)
2657 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002658
2659 if (wlv.extra_for_textprop)
2660 // wlv.extra_attr should be used at this position but
2661 // not any further.
2662 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002663 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002664
2665 wlv.extra_for_textprop = FALSE;
2666 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002667 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002668#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002669 }
2670 else
2671 {
2672#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002673 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002675 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002676
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002677 // Get a character from the line itself.
2678 c = *ptr;
2679#ifdef FEAT_LINEBREAK
2680 c0 = *ptr;
2681#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002682 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002683 {
2684#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002685 // text is finished, may display a "below" virtual text
2686 did_line = TRUE;
2687#endif
zeertzjqb557f482023-08-22 22:07:34 +02002688 // no more cells to skip
2689 skip_cells = 0;
2690 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002691
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002692 if (has_mbyte)
2693 {
2694 mb_c = c;
2695 if (enc_utf8)
2696 {
2697 // If the UTF-8 character is more than one byte: Decode it
2698 // into "mb_c".
2699 mb_l = utfc_ptr2len(ptr);
2700 mb_utf8 = FALSE;
2701 if (mb_l > 1)
2702 {
2703 mb_c = utfc_ptr2char(ptr, u8cc);
2704 // Overlong encoded ASCII or ASCII with composing char
2705 // is displayed normally, except a NUL.
2706 if (mb_c < 0x80)
2707 {
2708 c = mb_c;
2709#ifdef FEAT_LINEBREAK
2710 c0 = mb_c;
2711#endif
2712 }
2713 mb_utf8 = TRUE;
2714
2715 // At start of the line we can have a composing char.
2716 // Draw it as a space with a composing char.
2717 if (utf_iscomposing(mb_c))
2718 {
2719 int i;
2720
2721 for (i = Screen_mco - 1; i > 0; --i)
2722 u8cc[i] = u8cc[i - 1];
2723 u8cc[0] = mb_c;
2724 mb_c = ' ';
2725 }
2726 }
2727
2728 if ((mb_l == 1 && c >= 0x80)
2729 || (mb_l >= 1 && mb_c == 0)
2730 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2731 {
2732 // Illegal UTF-8 byte: display as <xx>.
2733 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002734 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002735# ifdef FEAT_RIGHTLEFT
2736 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002737 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002738# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002739 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002740 c = *wlv.p_extra;
2741 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002743 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2744 wlv.c_extra = NUL;
2745 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 if (area_attr == 0 && search_attr == 0)
2747 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002748 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002749 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002750 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002751 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002752 }
2753 }
2754 else if (mb_l == 0) // at the NUL at end-of-line
2755 mb_l = 1;
2756#ifdef FEAT_ARABIC
2757 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2758 {
2759 // Do Arabic shaping.
2760 int pc, pc1, nc;
2761 int pcc[MAX_MCO];
2762
2763 // The idea of what is the previous and next
2764 // character depends on 'rightleft'.
2765 if (wp->w_p_rl)
2766 {
2767 pc = prev_c;
2768 pc1 = prev_c1;
2769 nc = utf_ptr2char(ptr + mb_l);
2770 prev_c1 = u8cc[0];
2771 }
2772 else
2773 {
2774 pc = utfc_ptr2char(ptr + mb_l, pcc);
2775 nc = prev_c;
2776 pc1 = pcc[0];
2777 }
2778 prev_c = mb_c;
2779
2780 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2781 }
2782 else
2783 prev_c = mb_c;
2784#endif
2785 }
2786 else // enc_dbcs
2787 {
2788 mb_l = MB_BYTE2LEN(c);
2789 if (mb_l == 0) // at the NUL at end-of-line
2790 mb_l = 1;
2791 else if (mb_l > 1)
2792 {
2793 // We assume a second byte below 32 is illegal.
2794 // Hopefully this is OK for all double-byte encodings!
2795 if (ptr[1] >= 32)
2796 mb_c = (c << 8) + ptr[1];
2797 else
2798 {
2799 if (ptr[1] == NUL)
2800 {
2801 // head byte at end of line
2802 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002803 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002804 }
2805 else
2806 {
2807 // illegal tail byte
2808 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002809 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002810 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002811 wlv.p_extra = wlv.extra;
2812 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002813 wlv.c_extra = NUL;
2814 wlv.c_final = NUL;
2815 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002816 if (area_attr == 0 && search_attr == 0)
2817 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002818 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002819 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002820 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002821 // save current attr
2822 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002823 }
2824 mb_c = c;
2825 }
2826 }
2827 }
2828 // If a double-width char doesn't fit display a '>' in the
2829 // last column; the character is displayed at the start of the
2830 // next line.
2831 if ((
2832# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002835 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002836 && (*mb_char2cells)(mb_c) == 2)
2837 {
2838 c = '>';
2839 mb_c = c;
2840 mb_utf8 = FALSE;
2841 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002842 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002843 // Put pointer back so that the character will be
2844 // displayed at the start of the next line.
2845 --ptr;
2846#ifdef FEAT_CONCEAL
2847 did_decrement_ptr = TRUE;
2848#endif
2849 }
2850 else if (*ptr != NUL)
2851 ptr += mb_l - 1;
2852
2853 // If a double-width char doesn't fit at the left side display
2854 // a '<' in the first column. Don't do this for unprintable
2855 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002856 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002857 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002858 wlv.n_extra = 1;
2859 wlv.c_extra = MB_FILLER_CHAR;
2860 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 c = ' ';
2862 if (area_attr == 0 && search_attr == 0)
2863 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002864 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002865 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002866 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002867 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002868 }
2869 mb_c = c;
2870 mb_utf8 = FALSE;
2871 mb_l = 1;
2872 }
2873
2874 }
2875 ++ptr;
2876
2877 if (extra_check)
2878 {
2879#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002880 // Check spelling (unless at the end of the line).
2881 // Only do this when there is no syntax highlighting, the
2882 // @Spell cluster is not used or the current syntax item
2883 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002884 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002885 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002886 {
2887 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002888 // do not calculate cap_col at the end of the line or when
2889 // only white space is following
2890 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002891# ifdef FEAT_SYN_HL
2892 !has_syntax ||
2893# endif
2894 can_spell))
2895 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002896 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002897 int len;
2898 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002899
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002902
2903 // Use nextline[] if possible, it has the start of the
2904 // next line concatenated.
2905 if ((prev_ptr - line) - nextlinecol >= 0)
2906 p = nextline + (prev_ptr - line) - nextlinecol;
2907 else
2908 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002909 spv->spv_cap_col -= (int)(prev_ptr - line);
2910 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2911 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002912 word_end = v + len;
2913
2914 // In Insert mode only highlight a word that
2915 // doesn't touch the cursor.
2916 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002917 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002918 && wp->w_cursor.lnum == lnum
2919 && wp->w_cursor.col >=
2920 (colnr_T)(prev_ptr - line)
2921 && wp->w_cursor.col < (colnr_T)word_end)
2922 {
2923 spell_hlf = HLF_COUNT;
2924 spell_redraw_lnum = lnum;
2925 }
2926
2927 if (spell_hlf == HLF_COUNT && p != prev_ptr
2928 && (p - nextline) + len > nextline_idx)
2929 {
2930 // Remember that the good word continues at the
2931 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002932 spv->spv_checked_lnum = lnum + 1;
2933 spv->spv_checked_col = (p - nextline) + len
2934 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002935 }
2936
2937 // Turn index into actual attributes.
2938 if (spell_hlf != HLF_COUNT)
2939 spell_attr = highlight_attr[spell_hlf];
2940
Luuk van Baal30805a12023-05-27 22:22:10 +01002941 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002942 {
2943 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002944 && (p - nextline) + spv->spv_cap_col
2945 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 {
2947 // Remember that the word in the next line
2948 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002949 spv->spv_capcol_lnum = lnum + 1;
2950 spv->spv_cap_col = ((p - nextline)
2951 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002952 }
2953 else
2954 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002955 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 }
2957 }
2958 }
2959 if (spell_attr != 0)
2960 {
2961 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002962 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2963 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002964 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002965 wlv.char_attr = hl_combine_attr(spell_attr,
2966 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002967 }
2968#endif
2969#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002970 // we don't want linebreak to apply for lines that start with
2971 // leading spaces, followed by long letters (since it would add
2972 // a break at the beginning of a line and this might be unexpected)
2973 //
2974 // So only allow to linebreak, once we have found chars not in
2975 // 'breakat' in the line.
2976 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2977 !VIM_ISBREAK((int)*ptr))
2978 wlv.need_lbr = TRUE;
2979#endif
2980#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002982 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002983 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2984 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002985 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2986 : 0;
2987 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002988 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002989
zeertzjqce53e3e2023-09-01 18:49:30 +02002990 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2991# ifdef FEAT_PROP_POPUP
2992 - vcol_first_char,
2993# endif
2994 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002995# ifdef FEAT_PROP_POPUP
2996 // do not want virtual text counted here
2997 cts.cts_has_prop_with_text = FALSE;
2998# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002999 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003000 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003001
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003002 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003003 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003004 // line break, but for TABs the highlighting should
3005 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003006 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003007
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003009# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003010 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003011 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003012 wp->w_buffer->b_p_vts_array) - 1;
3013# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003015 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016# endif
3017
Bram Moolenaar1306b362022-08-06 15:59:06 +01003018 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3019 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003020# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003021 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003022 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003023# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003024 if (VIM_ISWHITE(c))
3025 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003026# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003027 if (c == TAB)
3028 // See "Tab alignment" below.
3029 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003030# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 if (!wp->w_p_list)
3032 c = ' ';
3033 }
3034 }
3035#endif
zeertzjqabc80812023-09-24 23:32:18 +02003036 if (wp->w_p_list)
3037 {
3038 in_multispace = c == ' ' && (*ptr == ' '
3039 || (prev_ptr > line && prev_ptr[-1] == ' '));
3040 if (!in_multispace)
3041 multispace_pos = 0;
3042 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003043
Bram Moolenaareed9d462021-02-15 20:38:25 +01003044 // 'list': Change char 160 to 'nbsp' and space to 'space'
3045 // setting in 'listchars'. But not when the character is
3046 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003047 if (wp->w_p_list
3048 && ((((c == 160 && mb_l == 1)
3049 || (mb_utf8
3050 && ((mb_c == 160 && mb_l == 2)
3051 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003052 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003053 || (c == ' '
3054 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003055 && (wp->w_lcs_chars.space
3056 || (in_multispace
3057 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003058 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003059 && ptr - line <= trailcol)))
3060 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003061 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3062 {
3063 c = wp->w_lcs_chars.multispace[multispace_pos++];
3064 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3065 multispace_pos = 0;
3066 }
3067 else
3068 c = (c == ' ') ? wp->w_lcs_chars.space
3069 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003070 if (area_attr == 0 && search_attr == 0)
3071 {
3072 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003073 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003074 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003075 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003076 }
3077 mb_c = c;
3078 if (enc_utf8 && utf_char2len(c) > 1)
3079 {
3080 mb_utf8 = TRUE;
3081 u8cc[0] = 0;
3082 c = 0xc0;
3083 }
3084 else
3085 mb_utf8 = FALSE;
3086 }
3087
zeertzjq2e7cba32022-06-10 15:30:32 +01003088 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3089 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003090 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003091 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3092 && wp->w_lcs_chars.leadmultispace != NULL)
3093 {
3094 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003095 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3096 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003097 multispace_pos = 0;
3098 }
3099
3100 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3101 c = wp->w_lcs_chars.trail;
3102
3103 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3104 c = wp->w_lcs_chars.lead;
3105
zeertzjq2e7cba32022-06-10 15:30:32 +01003106 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003107 c = wp->w_lcs_chars.space;
3108
3109
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003110 if (!attr_pri)
3111 {
3112 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003113 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003114 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003115 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003116 }
3117 mb_c = c;
3118 if (enc_utf8 && utf_char2len(c) > 1)
3119 {
3120 mb_utf8 = TRUE;
3121 u8cc[0] = 0;
3122 c = 0xc0;
3123 }
3124 else
3125 mb_utf8 = FALSE;
3126 }
3127 }
3128
3129 // Handling of non-printable characters.
3130 if (!vim_isprintc(c))
3131 {
3132 // when getting a character from the file, we may have to
3133 // turn it into something else on the way to putting it
3134 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003135 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003136 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003137 int tab_len = 0;
3138 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003139#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003140 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003141
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003142 // only adjust the tab_len, when at the first column
3143 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003144 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003145 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146#endif
3147 // tab amount depends on current column
3148#ifdef FEAT_VARTABS
3149 tab_len = tabstop_padding(vcol_adjusted,
3150 wp->w_buffer->b_p_ts,
3151 wp->w_buffer->b_p_vts_array) - 1;
3152#else
3153 tab_len = (int)wp->w_buffer->b_p_ts
3154 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3155#endif
3156
3157#ifdef FEAT_LINEBREAK
3158 if (!wp->w_p_lbr || !wp->w_p_list)
3159#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003160 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003161 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003162 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003163 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003164#ifdef FEAT_LINEBREAK
3165 else
3166 {
3167 char_u *p;
3168 int len;
3169 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003170 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003171
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003172# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003173 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003174 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003175 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003176
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003177 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003178 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003179 && old_boguscols > 0
3180 && wlv.n_extra > tab_len)
3181 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003182# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003183 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003184 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003185 // If wlv.n_extra > 0, it gives the number of chars
3186 // to use for a tab, else we need to calculate the
3187 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003188 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3189 len = tab_len * tab2_len;
3190 if (wp->w_lcs_chars.tab3)
3191 len += mb_char2len(wp->w_lcs_chars.tab3)
3192 - tab2_len;
3193 if (wlv.n_extra > 0)
3194 len += wlv.n_extra - tab_len;
3195 c = wp->w_lcs_chars.tab1;
3196 p = alloc(len + 1);
3197 if (p == NULL)
3198 wlv.n_extra = 0;
3199 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003200 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003201 vim_memset(p, ' ', len);
3202 p[len] = NUL;
3203 vim_free(wlv.p_extra_free);
3204 wlv.p_extra_free = p;
3205 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003206 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003207 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003208
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003209 if (*p == NUL)
3210 {
3211 tab_len = i;
3212 break;
3213 }
3214
3215 // if tab3 is given, use it for the last
3216 // char
3217 if (wp->w_lcs_chars.tab3
3218 && i == tab_len - 1)
3219 lcs = wp->w_lcs_chars.tab3;
3220 p += mb_char2bytes(lcs, p);
3221 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003222 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003223 }
3224 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003225# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003226 // n_extra will be increased by
3227 // FIX_FOX_BOGUSCOLS macro below, so need to
3228 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003229 if (wlv.vcol_off_co > 0)
3230 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003231# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003232 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003233 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003234 }
3235#endif
3236#ifdef FEAT_CONCEAL
3237 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003238 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003239
3240 // Tab alignment should be identical regardless of
3241 // 'conceallevel' value. So tab compensates of all
3242 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003243 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003244 // line. Note that the tab can be longer than
3245 // 'tabstop' when there are concealed characters.
3246 FIX_FOR_BOGUSCOLS;
3247
3248 // Make sure, the highlighting for the tab char will be
3249 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003250 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003251 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003252 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003253 tab_len += vc_saved;
3254 }
3255#endif
3256 mb_utf8 = FALSE; // don't draw as UTF-8
3257 if (wp->w_p_list)
3258 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003259 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003260 ? wp->w_lcs_chars.tab3
3261 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003262#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003263 if (wp->w_p_lbr && wlv.p_extra != NULL
3264 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003265 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266 else
3267#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003268 wlv.c_extra = wp->w_lcs_chars.tab2;
3269 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003271 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003272 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003273 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 mb_c = c;
3275 if (enc_utf8 && utf_char2len(c) > 1)
3276 {
3277 mb_utf8 = TRUE;
3278 u8cc[0] = 0;
3279 c = 0xc0;
3280 }
3281 }
3282 else
3283 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003284 wlv.c_final = NUL;
3285 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003286 c = ' ';
3287 }
3288 }
3289 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003290 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003291 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003292 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3293 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003294 && VIsual_mode != Ctrl_V
3295 && (
3296# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003299 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003300 && !(noinvcur
3301 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003302 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003303 && lcs_eol_one > 0)
3304 {
3305 // Display a '$' after the line or highlight an extra
3306 // character if the line break is included.
3307#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3308 // For a diff line the highlighting continues after the
3309 // "$".
3310 if (
3311# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003312 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003313# ifdef LINE_ATTR
3314 &&
3315# endif
3316# endif
3317# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003318 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003319# endif
3320 )
3321#endif
3322 {
3323 // In virtualedit, visual selections may extend
3324 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003325 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003326 && wlv.tocol != MAXCOL
3327 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003328 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003329 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003330 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003331 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3332 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003333 else
3334 c = ' ';
3335 lcs_eol_one = -1;
3336 --ptr; // put it back at the NUL
3337 if (!attr_pri)
3338 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003339 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003340 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003341 n_attr = 1;
3342 }
3343 mb_c = c;
3344 if (enc_utf8 && utf_char2len(c) > 1)
3345 {
3346 mb_utf8 = TRUE;
3347 u8cc[0] = 0;
3348 c = 0xc0;
3349 }
3350 else
3351 mb_utf8 = FALSE; // don't draw as UTF-8
3352 }
3353 else if (c != NUL)
3354 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003355 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3356 if (wlv.n_extra == 0)
3357 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003358#ifdef FEAT_RIGHTLEFT
3359 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003360 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003361#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003362 wlv.c_extra = NUL;
3363 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003364#ifdef FEAT_LINEBREAK
3365 if (wp->w_p_lbr)
3366 {
3367 char_u *p;
3368
Bram Moolenaar1306b362022-08-06 15:59:06 +01003369 c = *wlv.p_extra;
3370 p = alloc(wlv.n_extra + 1);
3371 vim_memset(p, ' ', wlv.n_extra);
3372 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3373 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003374 vim_free(wlv.p_extra_free);
3375 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003376 }
3377 else
3378#endif
3379 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003380 wlv.n_extra = byte2cells(c) - 1;
3381 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003382 }
3383 if (!attr_pri)
3384 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003385 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003386 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003387 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003388#ifdef FEAT_PROP_POPUP
3389 if (text_prop_type != NULL &&
3390 text_prop_flags & PT_FLAG_OVERRIDE)
3391 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3392#endif
3393
Bram Moolenaar1306b362022-08-06 15:59:06 +01003394 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003395 }
3396 mb_utf8 = FALSE; // don't draw as UTF-8
3397 }
3398 else if (VIsual_active
3399 && (VIsual_mode == Ctrl_V
3400 || VIsual_mode == 'v')
3401 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003402 && wlv.tocol != MAXCOL
3403 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003404 && (
3405#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003408 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003409 {
3410 c = ' ';
3411 --ptr; // put it back at the NUL
3412 }
3413#if defined(LINE_ATTR)
3414 else if ((
3415# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003416 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003417# endif
3418# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003419 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003421 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003422 ) && (
3423# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003426 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429# endif
3430 < wp->w_width)))
3431 {
3432 // Highlight until the right side of the window
3433 c = ' ';
3434 --ptr; // put it back at the NUL
3435
3436 // Remember we do the char for line highlighting.
3437 ++did_line_attr;
3438
3439 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003440 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003441 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003442 || (wp->w_p_list &&
3443 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003444 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003445#ifdef FEAT_SIGNS
3446 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003447 // but not when cursorline is active
3448 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3449 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003450 wlv.char_attr = wlv.sattr.sat_linehl;
3451#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003454 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003455 wlv.diff_hlf = HLF_CHD;
3456 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003458 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003459 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3460 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003461 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003462 || (wlv.vcol >= left_curline_col
3463 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003464 wlv.char_attr = hl_combine_attr(
3465 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003466 }
3467 }
3468# endif
3469# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003470 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003471 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003472 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003473 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3474 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 if (!wlv.cul_screenline
3477 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003478 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003479 wlv.char_attr = hl_combine_attr(
3480 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003481 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003482 else if (wlv.line_attr)
3483 wlv.char_attr = hl_combine_attr(
3484 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
3486# endif
3487 }
3488#endif
3489 }
3490
3491#ifdef FEAT_CONCEAL
3492 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003493 && (wp != curwin || lnum != wp->w_cursor.lnum
3494 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003495 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3496 && !(lnum_in_visual_area
3497 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3498 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003499 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003500 if (((prev_syntax_id != syntax_seqnr
3501 && (syntax_flags & HL_CONCEAL) != 0)
3502 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003503 && (syn_get_sub_char() != NUL
3504 || (has_match_conc && match_conc)
3505 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003506 && wp->w_p_cole != 3)
3507 {
3508 // First time at this concealed item: display one
3509 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003510 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003511 c = match_conc;
3512 else if (syn_get_sub_char() != NUL)
3513 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003514 else if (wp->w_lcs_chars.conceal != NUL)
3515 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003516 else
3517 c = ' ';
3518
zeertzjq010e1532024-03-14 18:22:17 +01003519 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3520 // When the first char to be concealed is double-width,
3521 // need to advance one more virtual column.
3522 wlv.n_extra++;
3523
3524 mb_c = c;
3525 if (enc_utf8 && utf_char2len(c) > 1)
3526 {
3527 mb_utf8 = TRUE;
3528 u8cc[0] = 0;
3529 c = 0xc0;
3530 }
3531 else
3532 mb_utf8 = FALSE; // don't draw as UTF-8
3533
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003534 prev_syntax_id = syntax_seqnr;
3535
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003537 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003538 wlv.vcol += wlv.n_extra;
3539 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003540 {
3541# ifdef FEAT_RIGHTLEFT
3542 if (wp->w_p_rl)
3543 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003544 wlv.col -= wlv.n_extra;
3545 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003546 }
3547 else
3548# endif
3549 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003550 wlv.boguscols += wlv.n_extra;
3551 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003552 }
3553 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003554 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003555 n_attr = 0;
3556 }
zeertzjqb557f482023-08-22 22:07:34 +02003557 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003558 {
3559 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003560 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003561 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 }
3563 else
3564 {
3565 prev_syntax_id = 0;
3566 is_concealing = FALSE;
3567 }
3568
zeertzjqb557f482023-08-22 22:07:34 +02003569 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003570 // not showing the '>', put pointer back to avoid getting stuck
3571 ++ptr;
3572
3573#endif // FEAT_CONCEAL
3574 }
3575
3576#ifdef FEAT_CONCEAL
3577 // In the cursor line and we may be concealing characters: correct
3578 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003579 // With 'virtualedit' we may never reach cursor position, but we still
3580 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003581 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003582 && wp == curwin && lnum == wp->w_cursor.lnum
3583 && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003584 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003586# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003588 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003590# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003591 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003592 if (wlv.vcol + skip_cells < wp->w_virtcol)
3593 // Cursor beyond end of the line with 'virtualedit'.
3594 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003596 did_wcol = TRUE;
3597 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003598# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003599 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003600# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003601 }
3602#endif
3603
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003604 // Use "wlv.extra_attr", but don't override visual selection
3605 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003606 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3607 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003608 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003609 && (!attr_pri
3610#ifdef FEAT_PROP_POPUP
3611 || (text_prop_flags & PT_FLAG_OVERRIDE)
3612#endif
3613 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003614 {
3615#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003616 if (wlv.line_attr)
3617 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618 else
3619#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003620 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003621#ifdef FEAT_PROP_POPUP
3622 if (reset_extra_attr)
3623 {
3624 reset_extra_attr = FALSE;
3625 wlv.extra_attr = 0;
3626 }
3627#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003628 }
3629
3630#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3631 // XIM don't send preedit_start and preedit_end, but they send
3632 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3633 // im_is_preediting() here.
3634 if (p_imst == IM_ON_THE_SPOT
3635 && xic != NULL
3636 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003637 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003638 && !p_imdisable
3639 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003640 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003641 {
3642 colnr_T tcol;
3643
3644 if (preedit_end_col == MAXCOL)
3645 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3646 else
3647 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003648 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003649 {
3650 if (feedback_old_attr < 0)
3651 {
3652 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003654 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003655 wlv.char_attr = im_get_feedback_attr(feedback_col);
3656 if (wlv.char_attr < 0)
3657 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 feedback_col++;
3659 }
3660 else if (feedback_old_attr >= 0)
3661 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003662 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003663 feedback_old_attr = -1;
3664 feedback_col = 0;
3665 }
3666 }
3667#endif
3668 // Handle the case where we are in column 0 but not on the first
3669 // character of the line and the user wants us to show us a
3670 // special character (via 'listchars' option "precedes:<char>".
3671 if (lcs_prec_todo != NUL
3672 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003673 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3674 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003676 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003678 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679 && c != NUL)
3680 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003681 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003682 lcs_prec_todo = NUL;
3683 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3684 {
3685 // Double-width character being overwritten by the "precedes"
3686 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003687 wlv.c_extra = MB_FILLER_CHAR;
3688 wlv.c_final = NUL;
3689 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003690 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003691 wlv.extra_attr =
3692 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003693 }
3694 mb_c = c;
3695 if (enc_utf8 && utf_char2len(c) > 1)
3696 {
3697 mb_utf8 = TRUE;
3698 u8cc[0] = 0;
3699 c = 0xc0;
3700 }
3701 else
3702 mb_utf8 = FALSE; // don't draw as UTF-8
3703 if (!attr_pri)
3704 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003705 saved_attr3 = wlv.char_attr; // save current attr
3706 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003707 n_attr3 = 1;
3708 }
3709 }
3710
3711 // At end of the text line or just after the last character.
3712 if ((c == NUL
3713#if defined(LINE_ATTR)
3714 || did_line_attr == 1
3715#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003716 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003717 {
3718#ifdef FEAT_SEARCH_EXTRA
3719 // flag to indicate whether prevcol equals startcol of search_hl or
3720 // one of the matches
3721 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3722 (long)(ptr - line) - (c == NUL));
3723#endif
3724 // Invert at least one char, used for Visual and empty line or
3725 // highlight match at end of line. If it's beyond the last
3726 // char on the screen, just overwrite that one (tricky!) Not
3727 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003728 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003729 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003730 && (VIsual_mode != Ctrl_V
3731 || lnum == VIsual.lnum
3732 || lnum == curwin->w_cursor.lnum)
3733 && c == NUL)
3734#ifdef FEAT_SEARCH_EXTRA
3735 // highlight 'hlsearch' match at end of line
3736 || (prevcol_hl_flag
3737# ifdef FEAT_SYN_HL
3738 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3739 && !(wp == curwin && VIsual_active))
3740# endif
3741# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003742 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003743# endif
3744# if defined(LINE_ATTR)
3745 && did_line_attr <= 1
3746# endif
3747 )
3748#endif
3749 ))
3750 {
3751 int n = 0;
3752
3753#ifdef FEAT_RIGHTLEFT
3754 if (wp->w_p_rl)
3755 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003756 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003757 n = 1;
3758 }
3759 else
3760#endif
3761 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003762 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003763 n = -1;
3764 }
3765 if (n != 0)
3766 {
3767 // At the window boundary, highlight the last character
3768 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003769 wlv.off += n;
3770 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003771 }
3772 else
3773 {
3774 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003777 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003778 }
3779#ifdef FEAT_SEARCH_EXTRA
3780 if (area_attr == 0)
3781 {
3782 // Use attributes from match with highest priority among
3783 // 'search_hl' and the match list.
3784 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003785 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003786 }
3787#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003788 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003789 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790#ifdef FEAT_RIGHTLEFT
3791 if (wp->w_p_rl)
3792 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003793 --wlv.col;
3794 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003795 }
3796 else
3797#endif
3798 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003799 ++wlv.col;
3800 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003801 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003802 ++wlv.vcol;
3803 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003804 }
3805 }
3806
3807 // At end of the text line.
3808 if (c == NUL)
3809 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003810#ifdef FEAT_PROP_POPUP
3811 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003812 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003813 // Put the pointer back to the NUL.
3814 --ptr;
3815 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003817 else
3818#endif
3819 {
3820 draw_screen_line(wp, &wlv);
3821
3822 // Update w_cline_height and w_cline_folded if the cursor line
3823 // was updated (saves a call to plines() later).
3824 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3825 {
3826 curwin->w_cline_row = startrow;
3827 curwin->w_cline_height = wlv.row - startrow;
3828#ifdef FEAT_FOLDING
3829 curwin->w_cline_folded = FALSE;
3830#endif
3831 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3832 }
3833 break;
3834 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003835 }
3836
3837 // Show "extends" character from 'listchars' if beyond the line end and
3838 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003839 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003840 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003841 && wp->w_p_list
3842 && !wp->w_p_wrap
3843#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003844 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845#endif
3846 && (
3847#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003850 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003851 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003852 || lcs_eol_one > 0
3853 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003854 || *wlv.p_extra != NUL))
3855#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003856 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003857#endif
3858 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003859 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003860 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003861 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003862 mb_c = c;
3863 if (enc_utf8 && utf_char2len(c) > 1)
3864 {
3865 mb_utf8 = TRUE;
3866 u8cc[0] = 0;
3867 c = 0xc0;
3868 }
3869 else
3870 mb_utf8 = FALSE;
3871 }
3872
3873#ifdef FEAT_SYN_HL
3874 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003875 if (wlv.draw_color_col)
3876 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003877
3878 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3879 // highlight the cursor position itself.
3880 // Also highlight the 'colorcolumn' if it is different than
3881 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003882 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3883 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003884 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003885 if (((wlv.draw_state == WL_LINE
3886 || wlv.draw_state == WL_BRI
3887 || wlv.draw_state == WL_SBR)
3888 && !lnum_in_visual_area
3889 && search_attr == 0
3890 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003891# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003892 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003893# endif
3894 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003895 {
3896 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3897 && lnum != wp->w_cursor.lnum)
3898 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003899 vcol_save_attr = wlv.char_attr;
3900 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3901 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003903 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003904 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003905 vcol_save_attr = wlv.char_attr;
3906 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003907 }
3908 }
3909#endif
3910
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003911 if (wlv.draw_state == WL_LINE)
3912 vcol_prev = wlv.vcol;
3913
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003914 // Store character to be displayed.
3915 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003916 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003917 {
3918 // Store the character.
3919#if defined(FEAT_RIGHTLEFT)
3920 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3921 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003922 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003923 --wlv.off;
3924 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003925 }
3926#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003927 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003928 if (enc_dbcs == DBCS_JPNU)
3929 {
3930 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003931 ScreenLines[wlv.off] = 0x8e;
3932 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003933 }
3934 else if (enc_utf8)
3935 {
3936 if (mb_utf8)
3937 {
3938 int i;
3939
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003942 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003943 for (i = 0; i < Screen_mco; ++i)
3944 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003945 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003946 if (u8cc[i] == 0)
3947 break;
3948 }
3949 }
3950 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003951 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003952 }
3953 if (multi_attr)
3954 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003955 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 multi_attr = 0;
3957 }
3958 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003959 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960
zeertzjqdb54e982023-09-21 16:33:09 +02003961 if (wlv.draw_state > WL_NR
3962#ifdef FEAT_DIFF
3963 && wlv.filler_todo <= 0
3964#endif
3965 )
3966 ScreenCols[wlv.off] = wlv.vcol;
3967 else
3968 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003969
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003970 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3971 {
3972 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003973 ++wlv.off;
3974 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003975 if (enc_utf8)
3976 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003977 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003978 else
3979 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003980 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003981
Bram Moolenaar1306b362022-08-06 15:59:06 +01003982 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003984 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003985#endif
3986 )
zeertzjqdb54e982023-09-21 16:33:09 +02003987 ScreenCols[wlv.off] = ++wlv.vcol;
3988 else
3989 ScreenCols[wlv.off] = -1;
3990
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003991 // When "wlv.tocol" is halfway a character, set it to the end
3992 // of the character, otherwise highlighting won't stop.
3993 if (wlv.tocol == wlv.vcol)
3994 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003995
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003996#ifdef FEAT_RIGHTLEFT
3997 if (wp->w_p_rl)
3998 {
3999 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004000 --wlv.off;
4001 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004002 }
4003#endif
4004 }
4005#ifdef FEAT_RIGHTLEFT
4006 if (wp->w_p_rl)
4007 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004008 --wlv.off;
4009 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004010 }
4011 else
4012#endif
4013 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004014 ++wlv.off;
4015 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004016 }
4017 }
4018#ifdef FEAT_CONCEAL
4019 else if (wp->w_p_cole > 0 && is_concealing)
4020 {
zeertzjq010e1532024-03-14 18:22:17 +01004021 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4022
zeertzjqb557f482023-08-22 22:07:34 +02004023 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004024 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004025 if (concealed_wide)
4026 {
4027 // When a double-width char is concealed,
4028 // need to advance one more virtual column.
4029 ++wlv.vcol;
4030 ++wlv.vcol_off_co;
4031 }
4032
Bram Moolenaar1306b362022-08-06 15:59:06 +01004033 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004034 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004035
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004036 if (wp->w_p_wrap)
4037 {
4038 // Special voodoo required if 'wrap' is on.
4039 //
4040 // Advance the column indicator to force the line
4041 // drawing to wrap early. This will make the line
4042 // take up the same screen space when parts are concealed,
4043 // so that cursor line computations aren't messed up.
4044 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004045 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004046 // trailing junk to be written out of the screen line
4047 // we are building, 'boguscols' keeps track of the number
4048 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004049 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004051 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004052# ifdef FEAT_RIGHTLEFT
4053 if (wp->w_p_rl)
4054 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004055 wlv.col -= wlv.n_extra;
4056 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004057 }
4058 else
4059# endif
4060 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004061 wlv.col += wlv.n_extra;
4062 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004063 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004064 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004065 n_attr = 0;
4066 }
4067
zeertzjq010e1532024-03-14 18:22:17 +01004068 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004069 {
4070 // Need to fill two screen columns.
4071# ifdef FEAT_RIGHTLEFT
4072 if (wp->w_p_rl)
4073 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004074 --wlv.boguscols;
4075 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004076 }
4077 else
4078# endif
4079 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004080 ++wlv.boguscols;
4081 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004082 }
4083 }
4084
4085# ifdef FEAT_RIGHTLEFT
4086 if (wp->w_p_rl)
4087 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004088 --wlv.boguscols;
4089 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004090 }
4091 else
4092# endif
4093 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004094 ++wlv.boguscols;
4095 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004096 }
4097 }
4098 else
4099 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004100 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004101 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004102 wlv.vcol += wlv.n_extra;
4103 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004104 n_attr = 0;
4105 }
4106 }
4107
4108 }
4109#endif // FEAT_CONCEAL
4110 else
zeertzjqb557f482023-08-22 22:07:34 +02004111 --skip_cells;
4112
4113 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4114 {
4115 wlv.vcol += skipped_cells;
4116 skipped_cells = 0;
4117 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004118
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004119 // Only advance the "wlv.vcol" when after the 'number' or
4120 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004121 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004123 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004124#endif
4125 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004126 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004127
4128#ifdef FEAT_SYN_HL
4129 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004130 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131#endif
4132
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004133 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004134 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4135 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004136
4137 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004138 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004139 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004140 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004141 if (wlv.n_attr_skip > 0)
4142 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004143
4144 // At end of screen line and there is more to come: Display the line
4145 // so far. If there is no more to display it is caught above.
4146 if ((
4147#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004148 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004149#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004150 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004151 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004152 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004154 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004155#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004156#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004157 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004158 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004159#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004160 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004161 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004162 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4163 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004164 )
4165 {
4166#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004167 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004168 // Apply 'cursorline' and 'wincolor' highlight.
4169 if (wlv.boguscols != 0 && (
4170# ifdef LINE_ATTR
4171 wlv.line_attr != 0 ||
4172# endif
4173 wlv.win_attr != 0
4174 )
4175 )
4176 {
4177 int attr = wlv.win_attr;
4178# ifdef LINE_ATTR
4179 if (wlv.line_attr != 0)
4180 attr = hl_combine_attr(attr, wlv.line_attr);
4181# endif
4182 while ((
4183# ifdef FEAT_RIGHTLEFT
4184 wp->w_p_rl ? wlv.col >= 0 :
4185# endif
4186 wlv.col < wp->w_width))
4187 {
4188 ScreenLines[wlv.off] = ' ';
4189 if (enc_utf8)
4190 ScreenLinesUC[wlv.off] = 0;
4191 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004192 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004193# ifdef FEAT_RIGHTLEFT
4194 if (wp->w_p_rl)
4195 {
4196 wlv.off--;
4197 wlv.col--;
4198 wlv.boguscols++;
4199 }
4200 else
4201# endif
4202 {
4203 wlv.off++;
4204 wlv.col++;
4205 wlv.boguscols--;
4206 }
4207 }
4208 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004209 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004210 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004211 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004212 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004214 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004215#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004216 ++wlv.row;
4217 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004218
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004219 // When not wrapping and finished diff lines, break here.
4220 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004221#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004222 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004223#endif
4224#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004225 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004226 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004227#endif
4228 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004229 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004230#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004231 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004232 {
4233 // do not output more of the line, only the "below" prop
4234 ptr += STRLEN(ptr);
4235# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004236 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004237# endif
4238 }
4239#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004240
4241 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004242 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004243#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004244 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004245#endif
4246 )
4247 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004248 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4249 draw_vsep_win(wp, wlv.row);
4250 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004251 }
4252
4253 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004254 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004255 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004256 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004257 break;
4258 }
4259
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004260 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004261#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004262 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004263#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004264#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004265 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004266#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004267 && wp->w_width == Columns)
4268 {
4269 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004270 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004271
4272 // Special trick to make copy/paste of wrapped lines work with
4273 // xterm/screen: write an extra character beyond the end of
4274 // the line. This will work with all terminal types
4275 // (regardless of the xn,am settings).
4276 // Only do this on a fast tty.
4277 // Only do this if the cursor is on the current line
4278 // (something has been written in it).
4279 // Don't do this for the GUI.
4280 // Don't do this for double-width characters.
4281 // Don't do this for a window not at the right screen border.
4282 if (p_tf
4283#ifdef FEAT_GUI
4284 && !gui.in_use
4285#endif
4286 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004287 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4288 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004289 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004290 || (*mb_off2cells)(
4291 LineOffset[wlv.screen_row - 1]
4292 + (int)Columns - 2,
4293 LineOffset[wlv.screen_row]
4294 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004295 {
4296 // First make sure we are at the end of the screen line,
4297 // then output the same character again to let the
4298 // terminal know about the wrap. If the terminal doesn't
4299 // auto-wrap, we overwrite the character.
4300 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004301 screen_char(LineOffset[wlv.screen_row - 1]
4302 + (unsigned)Columns - 1,
4303 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004304
4305 // When there is a multi-byte character, just output a
4306 // space to keep it simple.
4307 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004308 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004309 out_char(' ');
4310 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004311 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004312 + (Columns - 1)]);
4313 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004314 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004315 screen_start(); // don't know where cursor is now
4316 }
4317 }
4318
Bram Moolenaar1306b362022-08-06 15:59:06 +01004319 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004320
Bram Moolenaareed9d462021-02-15 20:38:25 +01004321 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004322#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004323 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004324# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004325 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004326# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004327 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004328 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004329#endif
4330#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004331 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004332 // When the filler lines are actually below the last line of the
4333 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004334 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004335 break;
4336#endif
4337 }
4338
4339 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004340#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004341 vim_free(text_props);
4342 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004343 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004344#endif
4345
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004346 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004347 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004348 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004349}