blob: 103760fa18921466cdb6200c803cdcba5d0d7b8e [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;
zeertzjq918b92b2024-03-20 19:49:20 +01001686 if (wlv.row >= endrow)
1687 {
1688 vim_free(text_props);
1689 vim_free(text_prop_idxs);
Bram Moolenaara572b932023-02-19 14:34:37 +00001690 return wlv.row;
zeertzjq918b92b2024-03-20 19:49:20 +01001691 }
Bram Moolenaara572b932023-02-19 14:34:37 +00001692 wlv.screen_row += wlv.text_prop_above_count;
1693 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001694#endif
1695
zeertzjqce53e3e2023-09-01 18:49:30 +02001696#if defined(FEAT_LINEBREAK) || defined(FEAT_PROP_POPUP)
1697 colnr_T vcol_first_char = 0;
zeertzjqebfd8562024-02-06 10:59:03 +01001698 if (wp->w_p_lbr && number_only == 0)
zeertzjqce53e3e2023-09-01 18:49:30 +02001699 {
1700 chartabsize_T cts;
1701 init_chartabsize_arg(&cts, wp, lnum, 0, line, line);
1702 (void)win_lbr_chartabsize(&cts, NULL);
1703 vcol_first_char = cts.cts_first_char;
1704 clear_chartabsize_arg(&cts);
1705 }
1706#endif
1707
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001708 // 'nowrap' or 'wrap' and a single line that doesn't fit: Advance to the
1709 // first character to be displayed.
1710 if (wp->w_p_wrap)
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00001711 v = startrow == 0 ? wp->w_skipcol - skipcol_in_text_prop_above : 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001712 else
1713 v = wp->w_leftcol;
zeertzjqebfd8562024-02-06 10:59:03 +01001714 if (v > 0 && number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001715 {
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001716 char_u *prev_ptr = ptr;
1717 chartabsize_T cts;
Bram Moolenaar6d023f92022-07-25 21:15:45 +01001718 int charsize = 0;
zeertzjqb557f482023-08-22 22:07:34 +02001719 int head = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001720
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001721 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol, line, ptr);
zeertzjqb557f482023-08-22 22:07:34 +02001722 cts.cts_max_head_vcol = v;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001723 while (cts.cts_vcol < v && *cts.cts_ptr != NUL)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001724 {
zeertzjqb557f482023-08-22 22:07:34 +02001725 head = 0;
1726 charsize = win_lbr_chartabsize(&cts, &head);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001727 cts.cts_vcol += charsize;
1728 prev_ptr = cts.cts_ptr;
1729 MB_PTR_ADV(cts.cts_ptr);
zeertzjqabc80812023-09-24 23:32:18 +02001730 if (wp->w_p_list)
1731 {
1732 in_multispace = *prev_ptr == ' ' && (*cts.cts_ptr == ' '
1733 || (prev_ptr > line && prev_ptr[-1] == ' '));
1734 if (!in_multispace)
1735 multispace_pos = 0;
1736 else if (cts.cts_ptr >= line + leadcol
1737 && wp->w_lcs_chars.multispace != NULL)
1738 {
1739 ++multispace_pos;
1740 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
1741 multispace_pos = 0;
1742 }
1743 else if (cts.cts_ptr < line + leadcol
1744 && wp->w_lcs_chars.leadmultispace != NULL)
1745 {
1746 ++multispace_pos;
1747 if (wp->w_lcs_chars.leadmultispace[multispace_pos] == NUL)
1748 multispace_pos = 0;
1749 }
1750 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001751 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001752 wlv.vcol = cts.cts_vcol;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01001753 ptr = cts.cts_ptr;
1754 clear_chartabsize_arg(&cts);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001755
1756 // When:
1757 // - 'cuc' is set, or
1758 // - 'colorcolumn' is set, or
1759 // - 'virtualedit' is set, or
1760 // - the visual mode is active,
1761 // the end of the line may be before the start of the displayed part.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001762 if (wlv.vcol < v && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001763#ifdef FEAT_SYN_HL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001764 wp->w_p_cuc || wlv.draw_color_col ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001765#endif
1766 virtual_active() ||
1767 (VIsual_active && wp->w_buffer == curwin->w_buffer)))
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001768 wlv.vcol = v;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001769
1770 // Handle a character that's not completely on the screen: Put ptr at
1771 // that character but skip the first few screen characters.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001772 if (wlv.vcol > v)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001773 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01001774 wlv.vcol -= charsize;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001775 ptr = prev_ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001776 }
zeertzjqb557f482023-08-22 22:07:34 +02001777 if (v > wlv.vcol)
1778 skip_cells = v - wlv.vcol - head;
Bram Moolenaarcd105412022-10-10 19:50:42 +01001779
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001780 // Adjust for when the inverted text is before the screen,
1781 // and when the start of the inverted text is before the screen.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001782 if (wlv.tocol <= wlv.vcol)
1783 wlv.fromcol = 0;
1784 else if (wlv.fromcol >= 0 && wlv.fromcol < wlv.vcol)
1785 wlv.fromcol = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001786
1787#ifdef FEAT_LINEBREAK
1788 // When w_skipcol is non-zero, first line needs 'showbreak'
1789 if (wp->w_p_wrap)
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001790 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001791#endif
1792#ifdef FEAT_SPELL
1793 // When spell checking a word we need to figure out the start of the
1794 // word and if it's badly spelled or not.
Luuk van Baal30805a12023-05-27 22:22:10 +01001795 if (spv->spv_has_spell)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001796 {
1797 int len;
1798 colnr_T linecol = (colnr_T)(ptr - line);
1799 hlf_T spell_hlf = HLF_COUNT;
1800
1801 pos = wp->w_cursor;
1802 wp->w_cursor.lnum = lnum;
1803 wp->w_cursor.col = linecol;
1804 len = spell_move_to(wp, FORWARD, TRUE, TRUE, &spell_hlf);
1805
1806 // spell_move_to() may call ml_get() and make "line" invalid
1807 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
1808 ptr = line + linecol;
1809
1810 if (len == 0 || (int)wp->w_cursor.col > ptr - line)
1811 {
1812 // no bad word found at line start, don't check until end of a
1813 // word
1814 spell_hlf = HLF_COUNT;
1815 word_end = (int)(spell_to_word_end(ptr, wp) - line + 1);
1816 }
1817 else
1818 {
1819 // bad word found, use attributes until end of word
1820 word_end = wp->w_cursor.col + len + 1;
1821
1822 // Turn index into actual attributes.
1823 if (spell_hlf != HLF_COUNT)
1824 spell_attr = highlight_attr[spell_hlf];
1825 }
1826 wp->w_cursor = pos;
1827
1828# ifdef FEAT_SYN_HL
1829 // Need to restart syntax highlighting for this line.
1830 if (has_syntax)
1831 syntax_start(wp, lnum);
1832# endif
1833 }
1834#endif
1835 }
1836
1837 // Correct highlighting for cursor that can't be disabled.
1838 // Avoids having to check this for each character.
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001839 if (wlv.fromcol >= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001840 {
1841 if (noinvcur)
1842 {
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001843 if ((colnr_T)wlv.fromcol == wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001844 {
1845 // highlighting starts at cursor, let it start just after the
1846 // cursor
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001847 fromcol_prev = wlv.fromcol;
1848 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001849 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001850 else if ((colnr_T)wlv.fromcol < wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001851 // restart highlighting after the cursor
1852 fromcol_prev = wp->w_virtcol;
1853 }
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001854 if (wlv.fromcol >= wlv.tocol)
1855 wlv.fromcol = -1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001856 }
1857
1858#ifdef FEAT_SEARCH_EXTRA
zeertzjqebfd8562024-02-06 10:59:03 +01001859 if (number_only == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001860 {
1861 v = (long)(ptr - line);
1862 area_highlighting |= prepare_search_hl_line(wp, lnum, (colnr_T)v,
1863 &line, &screen_search_hl,
1864 &search_attr);
1865 ptr = line + v; // "line" may have been updated
1866 }
1867#endif
1868
1869#ifdef FEAT_SYN_HL
1870 // Cursor line highlighting for 'cursorline' in the current window.
1871 if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
1872 {
1873 // Do not show the cursor line in the text when Visual mode is active,
zeertzjqc20e46a2022-03-23 14:55:23 +00001874 // because it's not clear what is selected then.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001875 if (!(wp == curwin && VIsual_active)
1876 && wp->w_p_culopt_flags != CULOPT_NBR)
1877 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001878 wlv.cul_screenline = (wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001879 && (wp->w_p_culopt_flags & CULOPT_SCRLINE));
1880
zeertzjqb7acea12022-12-12 13:20:43 +00001881 // Only apply CursorLine highlight here when "screenline" is not
1882 // present in 'cursorlineopt'. Otherwise it's done later.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001883 if (!wlv.cul_screenline)
zeertzjqb7acea12022-12-12 13:20:43 +00001884 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001885 else
1886 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001887 line_attr_save = wlv.line_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001888 margin_columns_win(wp, &left_curline_col, &right_curline_col);
1889 }
1890 area_highlighting = TRUE;
1891 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001892 }
1893#endif
1894
Bram Moolenaar1306b362022-08-06 15:59:06 +01001895 win_line_start(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001896
1897 // Repeat for the whole displayed line.
1898 for (;;)
1899 {
1900#if defined(FEAT_CONCEAL) || defined(FEAT_SEARCH_EXTRA)
Bram Moolenaarb9081882022-07-09 04:56:24 +01001901 int has_match_conc = 0; // match wants to conceal
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001902#endif
1903#ifdef FEAT_CONCEAL
Bram Moolenaarb9081882022-07-09 04:56:24 +01001904 int did_decrement_ptr = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001905#endif
Bram Moolenaarb9081882022-07-09 04:56:24 +01001906
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001907 // Skip this quickly when working on the text.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001908 if (wlv.draw_state != WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001909 {
zeertzjq4f33bc22021-08-05 17:57:02 +02001910#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01001911 if (wlv.cul_screenline)
zeertzjq4f33bc22021-08-05 17:57:02 +02001912 {
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001913 wlv.cul_attr = 0;
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00001914 wlv.line_attr = line_attr_save;
zeertzjq4f33bc22021-08-05 17:57:02 +02001915 }
1916#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001917 if (wlv.draw_state == WL_CMDLINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001918 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001919 wlv.draw_state = WL_CMDLINE;
Sean Dewar988f7432023-08-16 14:17:36 +01001920 if (wp == cmdwin_win)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001921 {
1922 // Draw the cmdline character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001923 wlv.n_extra = 1;
1924 wlv.c_extra = cmdwin_type;
1925 wlv.c_final = NUL;
Bram Moolenaard7657e92022-09-20 18:59:30 +01001926 wlv.char_attr =
1927 hl_combine_attr(wlv.wcr_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001928 }
1929 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001930#ifdef FEAT_FOLDING
Bram Moolenaar1306b362022-08-06 15:59:06 +01001931 if (wlv.draw_state == WL_FOLD - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001932 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001933 wlv.draw_state = WL_FOLD;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001934 handle_foldcolumn(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001935 }
1936#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001937#ifdef FEAT_SIGNS
Bram Moolenaar1306b362022-08-06 15:59:06 +01001938 if (wlv.draw_state == WL_SIGN - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001939 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001940 // Show the sign column when desired or when using Netbeans.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001941 wlv.draw_state = WL_SIGN;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001942 if (signcolumn_on(wp))
Bram Moolenaard7657e92022-09-20 18:59:30 +01001943 get_sign_display_info(FALSE, wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001944 }
1945#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001946 if (wlv.draw_state == WL_NR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001947 {
Bram Moolenaard7657e92022-09-20 18:59:30 +01001948 // Show the line number, if desired.
Bram Moolenaar1306b362022-08-06 15:59:06 +01001949 wlv.draw_state = WL_NR;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001950 handle_lnum_col(wp, &wlv, sign_present, num_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001951 }
zeertzjqebfd8562024-02-06 10:59:03 +01001952
1953 // When only displaying the (relative) line number and that's done,
1954 // stop here.
1955 if (number_only > 0 && wlv.draw_state == WL_NR && wlv.n_extra == 0)
1956 {
zeertzjqd0c1b772024-03-16 15:03:33 +01001957 wlv_screen_line(wp, &wlv, FALSE);
zeertzjqebfd8562024-02-06 10:59:03 +01001958 // Need to update more screen lines if:
1959 // - LineNrAbove or LineNrBelow is used, or
1960 // - still drawing filler lines.
1961 if ((wlv.row + 1 - wlv.startrow < number_only
1962 && (HL_ATTR(HLF_LNA) != 0 || HL_ATTR(HLF_LNB) != 0))
1963#ifdef FEAT_DIFF
1964 || wlv.filler_todo > 0
1965#endif
1966 )
1967 {
1968 ++wlv.row;
1969 ++wlv.screen_row;
1970 if (wlv.row == endrow)
1971 break;
1972#ifdef FEAT_DIFF
1973 --wlv.filler_todo;
1974 if (wlv.filler_todo == 0 && wp->w_botfill)
1975 break;
1976#endif
1977 win_line_start(wp, &wlv, TRUE);
1978 continue;
1979 }
1980 else
1981 break;
1982 }
1983
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001984#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01001985 // Check if 'breakindent' applies and show it.
1986 // May change wlv.draw_state to WL_BRI or WL_BRI - 1.
1987 if (wlv.n_extra == 0)
1988 handle_breakindent(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001989#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001990#if defined(FEAT_LINEBREAK) || defined(FEAT_DIFF)
Bram Moolenaar1306b362022-08-06 15:59:06 +01001991 if (wlv.draw_state == WL_SBR - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001992 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001993 wlv.draw_state = WL_SBR;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01001994 handle_showbreak_and_filler(wp, &wlv);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001995 }
1996#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01001997 if (wlv.draw_state == WL_LINE - 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02001998 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01001999 wlv.draw_state = WL_LINE;
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002000 win_line_continue(&wlv); // use wlv.saved_ values
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002001 }
2002 }
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002003
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002004#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002005 if (wlv.cul_screenline && wlv.draw_state == WL_LINE
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002006 && wlv.vcol >= left_curline_col
2007 && wlv.vcol < right_curline_col)
zeertzjqb7acea12022-12-12 13:20:43 +00002008 apply_cursorline_highlight(&wlv, sign_present);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002009#endif
2010
2011 // When still displaying '$' of change command, stop at cursor.
zeertzjqebfd8562024-02-06 10:59:03 +01002012 if (dollar_vcol >= 0 && wp == curwin
2013 && lnum == wp->w_cursor.lnum
2014 && wlv.vcol >= (long)wp->w_virtcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002015 {
zeertzjqd0c1b772024-03-16 15:03:33 +01002016 wlv_screen_line(wp, &wlv, FALSE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002017 // Pretend we have finished updating the window. Except when
2018 // 'cursorcolumn' is set.
2019#ifdef FEAT_SYN_HL
2020 if (wp->w_p_cuc)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002021 wlv.row = wp->w_cline_row + wp->w_cline_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002022 else
2023#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002024 wlv.row = wp->w_height;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002025 break;
2026 }
2027
Bram Moolenaar1306b362022-08-06 15:59:06 +01002028 if (wlv.draw_state == WL_LINE && (area_highlighting || extra_check))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002029 {
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002030#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002031 if (text_props != NULL)
2032 {
2033 int pi;
2034 int bcol = (int)(ptr - line);
2035
Bram Moolenaar1306b362022-08-06 15:59:06 +01002036 if (wlv.n_extra > 0
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002037# ifdef FEAT_LINEBREAK
2038 && !in_linebreak
2039# endif
2040 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002041 --bcol; // still working on the previous char, e.g. Tab
2042
2043 // Check if any active property ends.
2044 for (pi = 0; pi < text_props_active; ++pi)
2045 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002046 int tpi = text_prop_idxs[pi];
2047 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002048
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002049 // An inline property ends when after the start column plus
2050 // length. An "above" property ends when used and n_extra
2051 // is zero.
2052 if ((tp->tp_col != MAXCOL
2053 && bcol >= tp->tp_col - 1 + tp->tp_len))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002054 {
2055 if (pi + 1 < text_props_active)
2056 mch_memmove(text_prop_idxs + pi,
2057 text_prop_idxs + pi + 1,
2058 sizeof(int)
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002059 * (text_props_active - (pi + 1)));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002060 --text_props_active;
2061 --pi;
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002062# ifdef FEAT_LINEBREAK
2063 // not exactly right but should work in most cases
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002064 if (in_linebreak && syntax_attr == text_prop_attr_comb)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002065 syntax_attr = 0;
2066# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002067 }
2068 }
2069
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002070# ifdef FEAT_LINEBREAK
Bram Moolenaar1306b362022-08-06 15:59:06 +01002071 if (wlv.n_extra > 0 && in_linebreak)
Bram Moolenaaracdc9112021-12-02 19:46:57 +00002072 // not on the next char yet, don't start another prop
2073 --bcol;
2074# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002075 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002076 // With 'nowrap' and not in the first screen line only "below"
2077 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002078 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002079 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002080 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002081 && (wp->w_p_wrap
2082 || wlv.row == startrow
2083 || (text_props[text_prop_next].tp_flags
2084 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002085 || (bcol == 0
2086 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002087 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002088 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002089 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002090 if (text_props[text_prop_next].tp_col == MAXCOL
2091 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002092 + text_props[text_prop_next].tp_len)
2093 text_prop_idxs[text_props_active++] = text_prop_next;
2094 ++text_prop_next;
2095 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002096
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002097 if (wlv.n_extra == 0 ||
2098 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002099 && !(text_prop_type != NULL &&
2100 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002101 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002102 {
2103 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002104 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002105 text_prop_flags = 0;
2106 text_prop_type = NULL;
2107 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002108 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002109 }
Dylan Thacker-Smithc8b47f22024-03-26 18:05:01 +01002110 if (text_props_active > 0 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002111 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002112 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002113 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002114 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002115
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002116 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002117 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002118
2119 // Sort the properties on priority and/or starting last.
2120 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002121 sort_text_props(wp->w_buffer, text_props,
2122 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002123
2124 for (pi = 0; pi < text_props_active; ++pi)
2125 {
2126 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002127 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002128 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002129 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002130
Bram Moolenaarcd105412022-10-10 19:50:42 +01002131 // Only use a text property that can be displayed.
2132 // Skip "after" properties when wrap is off and at the
2133 // end of the window.
2134 if (pt != NULL
2135 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2136 && tp->tp_id != -MAXCOL
2137 && !(tp->tp_id < 0
2138 && !wp->w_p_wrap
2139 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2140 | TP_FLAG_ALIGN_ABOVE
2141 | TP_FLAG_ALIGN_BELOW)) == 0
2142 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002143 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002144 if (tp->tp_col == MAXCOL
2145 && *ptr == NUL
2146 && ((wp->w_p_list && lcs_eol_one > 0
2147 && (tp->tp_flags
2148 & TP_FLAG_ALIGN_ABOVE) == 0)
2149 || (ptr == line
2150 && !did_line
2151 && (tp->tp_flags
2152 & TP_FLAG_ALIGN_BELOW))))
2153 {
2154 // skip this prop, first display the '$' after
2155 // the line or display an empty line
2156 text_prop_follows = TRUE;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002157 continue;
2158 }
2159
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002160 if (pt->pt_hl_id > 0)
2161 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002162 text_prop_type = pt;
2163 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002164 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002165 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2166 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002167 text_prop_flags = pt->pt_flags;
2168 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 used_tpi = tpi;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002170 }
2171 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002172 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002173 && -text_prop_id
2174 <= wp->w_buffer->b_textprop_text.ga_len)
2175 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002176 textprop_T *tp = &text_props[used_tpi];
2177 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002178 ->b_textprop_text.ga_data)[
2179 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002180 int above = (tp->tp_flags
2181 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002182 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002183
2184 // reset the ID in the copy to avoid it being used
2185 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002186 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002187
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002188 if (p != NULL)
2189 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002190 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002191 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002192 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002193 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002194 int wrap = tp->tp_col < MAXCOL
2195 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002196 int padding = tp->tp_col == MAXCOL
2197 && tp->tp_len > 1
2198 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002199
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002200 // Insert virtual text before the current
2201 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002202 wlv.p_extra = p;
2203 wlv.c_extra = NUL;
2204 wlv.c_final = NUL;
2205 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002206 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002207 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002208 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2209 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002210 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002211 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002212 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002213 if (*ptr == NUL)
2214 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002215 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002216# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002217 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002218 {
2219 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002220 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002221 wlv.need_showbreak = FALSE;
2222 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002223 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002224# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002225 if ((right || above || below || !wrap
2226 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002227 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002228 char_u *prev_p_extra = wlv.p_extra;
2229 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002230
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002231 // Take care of padding, right-align and
2232 // truncation.
2233 // Shared with win_lbr_chartabsize(), must do
2234 // exactly the same.
2235 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002236 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002237# ifdef FEAT_RIGHTLEFT
2238 wp->w_p_rl
2239 ? wp->w_width - wlv.col - 1
2240 :
2241# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002242 wlv.col,
2243 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002244 &n_attr, &wlv.n_attr_skip,
2245 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002246 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002247 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002248 // wlv.p_extra was allocated
2249 vim_free(p_extra_free2);
2250 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002251 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002252
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002253 if (above)
2254 wlv.vcol_off_tp = wlv.n_extra;
2255
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002256 if (lcs_eol_one < 0
2257 && wp->w_p_wrap
2258 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002259 + wlv.n_extra - 2 > wp->w_width)
2260 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002261 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002262
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002263 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002264 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002265 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002266 {
2267 draw_screen_line(wp, &wlv);
2268
2269 // When line got too long for screen break
2270 // here.
2271 if (wlv.row == endrow)
2272 {
2273 ++wlv.row;
2274 break;
2275 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002276 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002277 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002278 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002279 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002280 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002281
Bram Moolenaarcd105412022-10-10 19:50:42 +01002282 // If the text didn't reach until the first window
2283 // column we need to skip cells.
2284 if (skip_cells > 0)
2285 {
2286 if (wlv.n_extra > skip_cells)
2287 {
2288 wlv.n_extra -= skip_cells;
2289 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002290 wlv.n_attr_skip -= skip_cells;
2291 if (wlv.n_attr_skip < 0)
2292 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002293 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002294 skip_cells = 0;
2295 }
2296 else
2297 {
2298 // the whole text is left of the window, drop
2299 // it and advance to the next one
2300 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002301 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002302 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002303 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002304 bail_out = TRUE;
2305 }
2306 }
2307
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002308 // If another text prop follows the condition below at
2309 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002310 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002311 // must wrap anyway.
2312 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002313 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002314 && (wp->w_p_wrap
2315 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002316 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002317
2318 if (bail_out)
2319 // starting a new line for "below"
2320 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002321 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002322 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002323 else if (text_prop_next < text_prop_count
2324 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002325 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2326 || (!wp->w_p_wrap
2327 && wlv.col == wp->w_width - 1
2328 && (text_props[text_prop_next].tp_flags
2329 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002330 // When at last-but-one character and a text property
2331 // follows after it, we may need to flush the line after
2332 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002333 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002334 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002335 }
zeertzjq6e940d92023-08-17 23:21:40 +02002336
2337 if (wlv.start_extra_for_textprop)
2338 {
2339 wlv.start_extra_for_textprop = FALSE;
2340 // restore search_attr and area_attr when n_extra
2341 // is down to zero
2342 saved_search_attr = search_attr;
2343 saved_area_attr = area_attr;
2344 search_attr = 0;
2345 area_attr = 0;
2346 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002347#endif
2348
zeertzjq6e940d92023-08-17 23:21:40 +02002349 int *area_attr_p =
2350#ifdef FEAT_PROP_POPUP
2351 wlv.extra_for_textprop ? &saved_area_attr :
2352#endif
2353 &area_attr;
2354
2355 // handle Visual or match highlighting in this line
2356 if (wlv.vcol == wlv.fromcol
2357 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2358 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2359 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2360 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2361 || ((int)vcol_prev == fromcol_prev
2362 && vcol_prev < wlv.vcol // not at margin
2363 && wlv.vcol < wlv.tocol))
2364 *area_attr_p = vi_attr; // start highlighting
2365 else if (*area_attr_p != 0
2366 && (wlv.vcol == wlv.tocol
2367 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2368 *area_attr_p = 0; // stop highlighting
2369
zeertzjqe500ae82023-08-17 22:35:26 +02002370#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002371 if (wlv.n_extra == 0)
2372 {
2373 // Check for start/end of 'hlsearch' and other matches.
2374 // After end, check for start/end of next match.
2375 // When another match, have to check for start again.
2376 v = (long)(ptr - line);
2377 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2378 &screen_search_hl, &has_match_conc,
2379 &match_conc, did_line_attr, lcs_eol_one,
2380 &on_last_col);
2381 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002382
2383 // Do not allow a conceal over EOL otherwise EOL will be missed
2384 // and bad things happen.
2385 if (*ptr == NUL)
2386 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002387 }
zeertzjqe500ae82023-08-17 22:35:26 +02002388#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002389
Bram Moolenaare38fc862022-08-11 17:24:50 +01002390#ifdef FEAT_DIFF
2391 if (wlv.diff_hlf != (hlf_T)0)
2392 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002393 // When there is extra text (e.g. virtual text) it gets the
2394 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002395 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2396 && wlv.n_extra == 0)
2397 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002398 if (wlv.diff_hlf == HLF_TXD
2399 && ((ptr - line > change_end && wlv.n_extra == 0)
2400 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002401 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002402 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002403 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2404 && wp->w_p_culopt_flags != CULOPT_NBR
2405 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2406 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002407 wlv.line_attr = hl_combine_attr(
2408 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002409 }
2410#endif
2411
Bram Moolenaara74fda62019-10-19 17:38:03 +02002412#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002413 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002414 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002415 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002416# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002417 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002418 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002419# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002420 // Get syntax attribute.
2421 if (has_syntax)
2422 {
2423 // Get the syntax attribute for the character. If there
2424 // is an error, disable syntax highlighting.
2425 save_did_emsg = did_emsg;
2426 did_emsg = FALSE;
2427
2428 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002429 if (v == prev_syntax_col)
2430 // at same column again
2431 syntax_attr = prev_syntax_attr;
2432 else
2433 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002434# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002435 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002436# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002437 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002438# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002439 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002440# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002441 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002442 prev_syntax_col = v;
2443 prev_syntax_attr = syntax_attr;
2444 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002445
Bram Moolenaar34390282019-10-16 14:38:26 +02002446 if (did_emsg)
2447 {
2448 wp->w_s->b_syn_error = TRUE;
2449 has_syntax = FALSE;
2450 syntax_attr = 0;
2451 }
2452 else
2453 did_emsg = save_did_emsg;
2454# ifdef SYN_TIME_LIMIT
2455 if (wp->w_s->b_syn_slow)
2456 has_syntax = FALSE;
2457# endif
2458
2459 // Need to get the line again, a multi-line regexp may
2460 // have made it invalid.
2461 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2462 ptr = line + v;
2463# ifdef FEAT_CONCEAL
2464 // no concealing past the end of the line, it interferes
2465 // with line highlighting
2466 if (*ptr == NUL)
2467 syntax_flags = 0;
2468 else
2469 syntax_flags = get_syntax_info(&syntax_seqnr);
2470# endif
2471 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002472 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002473# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002474 // Combine text property highlight into syntax highlight.
2475 if (text_prop_type != NULL)
2476 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002477 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002478 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2479 else
2480 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002481 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002482 }
2483# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002484#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002485
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002486 // Decide which of the highlight attributes to use.
2487 attr_pri = TRUE;
2488#ifdef LINE_ATTR
2489 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002490 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002491 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002492 if (!highlight_match)
2493 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002494 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002495# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002496 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002497# endif
2498 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002499 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002500 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002501 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002502# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002503 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002504# endif
2505 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002506 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002507 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2508 || wlv.vcol < wlv.fromcol
2509 || vcol_prev < fromcol_prev
2510 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002511 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002512 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002513 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002514# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002515 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002516# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002517 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002518# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 attr_pri = FALSE;
2520 }
2521#else
2522 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002523 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002524 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002525 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002526#endif
2527 else
2528 {
2529 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002532#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002533 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002534#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002535 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002536#ifdef FEAT_PROP_POPUP
2537 // override with text property highlight when "override" is TRUE
2538 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002540#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002542
2543 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002544 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002545 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002546 if (wlv.char_attr == 0)
2547 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002548 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002549 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002550 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002551
2552 // Get the next character to put on the screen.
2553
2554 // The "p_extra" points to the extra stuff that is inserted to
2555 // represent special characters (non-printable stuff) and other
2556 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002557 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002558 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2559 // "p_extra[n_extra]".
2560 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002561 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002562 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002565 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2566 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002567 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2568 if (enc_utf8 && utf_char2len(c) > 1)
2569 {
2570 mb_utf8 = TRUE;
2571 u8cc[0] = 0;
2572 c = 0xc0;
2573 }
2574 else
2575 mb_utf8 = FALSE;
2576 }
2577 else
2578 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002579 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002580 if (has_mbyte)
2581 {
2582 mb_c = c;
2583 if (enc_utf8)
2584 {
2585 // If the UTF-8 character is more than one byte:
2586 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002587 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002588 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002589 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002590 mb_l = 1;
2591 else if (mb_l > 1)
2592 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 mb_utf8 = TRUE;
2595 c = 0xc0;
2596 }
2597 }
2598 else
2599 {
2600 // if this is a DBCS character, put it in "mb_c"
2601 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002602 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002603 mb_l = 1;
2604 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002605 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002606 }
2607 if (mb_l == 0) // at the NUL at end-of-line
2608 mb_l = 1;
2609
2610 // If a double-width char doesn't fit display a '>' in the
2611 // last column.
2612 if ((
2613# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002614 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002615# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002616 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002617 && (*mb_char2cells)(mb_c) == 2)
2618 {
2619 c = '>';
2620 mb_c = c;
2621 mb_l = 1;
2622 mb_utf8 = FALSE;
2623 multi_attr = HL_ATTR(HLF_AT);
2624#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002625 if (wlv.cul_attr)
2626 multi_attr = hl_combine_attr(
2627 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002628#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002629 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002630
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002631 // put the pointer back to output the double-width
2632 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002633 ++wlv.n_extra;
2634 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002635 }
2636 else
2637 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002638 wlv.n_extra -= mb_l - 1;
2639 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002640 }
2641 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002642 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002643 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002645#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002646 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002647 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002648 // Only restore search_attr and area_attr after "n_extra" in
2649 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002650 if (wlv.saved_n_extra <= 0)
2651 {
2652 if (search_attr == 0)
2653 search_attr = saved_search_attr;
2654 if (area_attr == 0 && *ptr != NUL)
2655 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002656
2657 if (wlv.extra_for_textprop)
2658 // wlv.extra_attr should be used at this position but
2659 // not any further.
2660 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002661 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002662
2663 wlv.extra_for_textprop = FALSE;
2664 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002665 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002666#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002667 }
2668 else
2669 {
2670#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002671 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002672#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002673 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002674
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002675 // Get a character from the line itself.
2676 c = *ptr;
2677#ifdef FEAT_LINEBREAK
2678 c0 = *ptr;
2679#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002680 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002681 {
2682#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002683 // text is finished, may display a "below" virtual text
2684 did_line = TRUE;
2685#endif
zeertzjqb557f482023-08-22 22:07:34 +02002686 // no more cells to skip
2687 skip_cells = 0;
2688 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002689
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002690 if (has_mbyte)
2691 {
2692 mb_c = c;
2693 if (enc_utf8)
2694 {
2695 // If the UTF-8 character is more than one byte: Decode it
2696 // into "mb_c".
2697 mb_l = utfc_ptr2len(ptr);
2698 mb_utf8 = FALSE;
2699 if (mb_l > 1)
2700 {
2701 mb_c = utfc_ptr2char(ptr, u8cc);
2702 // Overlong encoded ASCII or ASCII with composing char
2703 // is displayed normally, except a NUL.
2704 if (mb_c < 0x80)
2705 {
2706 c = mb_c;
2707#ifdef FEAT_LINEBREAK
2708 c0 = mb_c;
2709#endif
2710 }
2711 mb_utf8 = TRUE;
2712
2713 // At start of the line we can have a composing char.
2714 // Draw it as a space with a composing char.
2715 if (utf_iscomposing(mb_c))
2716 {
2717 int i;
2718
2719 for (i = Screen_mco - 1; i > 0; --i)
2720 u8cc[i] = u8cc[i - 1];
2721 u8cc[0] = mb_c;
2722 mb_c = ' ';
2723 }
2724 }
2725
2726 if ((mb_l == 1 && c >= 0x80)
2727 || (mb_l >= 1 && mb_c == 0)
2728 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2729 {
2730 // Illegal UTF-8 byte: display as <xx>.
2731 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002732 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002733# ifdef FEAT_RIGHTLEFT
2734 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002735 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002736# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002737 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002738 c = *wlv.p_extra;
2739 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002740 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002741 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2742 wlv.c_extra = NUL;
2743 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002744 if (area_attr == 0 && search_attr == 0)
2745 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002746 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002747 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002748 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002749 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 }
2751 }
2752 else if (mb_l == 0) // at the NUL at end-of-line
2753 mb_l = 1;
2754#ifdef FEAT_ARABIC
2755 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2756 {
2757 // Do Arabic shaping.
2758 int pc, pc1, nc;
2759 int pcc[MAX_MCO];
2760
2761 // The idea of what is the previous and next
2762 // character depends on 'rightleft'.
2763 if (wp->w_p_rl)
2764 {
2765 pc = prev_c;
2766 pc1 = prev_c1;
2767 nc = utf_ptr2char(ptr + mb_l);
2768 prev_c1 = u8cc[0];
2769 }
2770 else
2771 {
2772 pc = utfc_ptr2char(ptr + mb_l, pcc);
2773 nc = prev_c;
2774 pc1 = pcc[0];
2775 }
2776 prev_c = mb_c;
2777
2778 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2779 }
2780 else
2781 prev_c = mb_c;
2782#endif
2783 }
2784 else // enc_dbcs
2785 {
2786 mb_l = MB_BYTE2LEN(c);
2787 if (mb_l == 0) // at the NUL at end-of-line
2788 mb_l = 1;
2789 else if (mb_l > 1)
2790 {
2791 // We assume a second byte below 32 is illegal.
2792 // Hopefully this is OK for all double-byte encodings!
2793 if (ptr[1] >= 32)
2794 mb_c = (c << 8) + ptr[1];
2795 else
2796 {
2797 if (ptr[1] == NUL)
2798 {
2799 // head byte at end of line
2800 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002801 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002802 }
2803 else
2804 {
2805 // illegal tail byte
2806 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002807 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002809 wlv.p_extra = wlv.extra;
2810 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002811 wlv.c_extra = NUL;
2812 wlv.c_final = NUL;
2813 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 if (area_attr == 0 && search_attr == 0)
2815 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002816 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002817 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002818 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002819 // save current attr
2820 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002821 }
2822 mb_c = c;
2823 }
2824 }
2825 }
2826 // If a double-width char doesn't fit display a '>' in the
2827 // last column; the character is displayed at the start of the
2828 // next line.
2829 if ((
2830# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002831 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002832# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002833 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002834 && (*mb_char2cells)(mb_c) == 2)
2835 {
2836 c = '>';
2837 mb_c = c;
2838 mb_utf8 = FALSE;
2839 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002840 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002841 // Put pointer back so that the character will be
2842 // displayed at the start of the next line.
2843 --ptr;
2844#ifdef FEAT_CONCEAL
2845 did_decrement_ptr = TRUE;
2846#endif
2847 }
2848 else if (*ptr != NUL)
2849 ptr += mb_l - 1;
2850
2851 // If a double-width char doesn't fit at the left side display
2852 // a '<' in the first column. Don't do this for unprintable
2853 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002854 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002855 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002856 wlv.n_extra = 1;
2857 wlv.c_extra = MB_FILLER_CHAR;
2858 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002859 c = ' ';
2860 if (area_attr == 0 && search_attr == 0)
2861 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002863 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002864 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002865 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002866 }
2867 mb_c = c;
2868 mb_utf8 = FALSE;
2869 mb_l = 1;
2870 }
2871
2872 }
2873 ++ptr;
2874
2875 if (extra_check)
2876 {
2877#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002878 // Check spelling (unless at the end of the line).
2879 // Only do this when there is no syntax highlighting, the
2880 // @Spell cluster is not used or the current syntax item
2881 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002882 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002883 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 {
2885 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002886 // do not calculate cap_col at the end of the line or when
2887 // only white space is following
2888 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002889# ifdef FEAT_SYN_HL
2890 !has_syntax ||
2891# endif
2892 can_spell))
2893 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002894 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895 int len;
2896 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002897
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002898 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002899 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002900
2901 // Use nextline[] if possible, it has the start of the
2902 // next line concatenated.
2903 if ((prev_ptr - line) - nextlinecol >= 0)
2904 p = nextline + (prev_ptr - line) - nextlinecol;
2905 else
2906 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002907 spv->spv_cap_col -= (int)(prev_ptr - line);
2908 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2909 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002910 word_end = v + len;
2911
2912 // In Insert mode only highlight a word that
2913 // doesn't touch the cursor.
2914 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002915 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 && wp->w_cursor.lnum == lnum
2917 && wp->w_cursor.col >=
2918 (colnr_T)(prev_ptr - line)
2919 && wp->w_cursor.col < (colnr_T)word_end)
2920 {
2921 spell_hlf = HLF_COUNT;
2922 spell_redraw_lnum = lnum;
2923 }
2924
2925 if (spell_hlf == HLF_COUNT && p != prev_ptr
2926 && (p - nextline) + len > nextline_idx)
2927 {
2928 // Remember that the good word continues at the
2929 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002930 spv->spv_checked_lnum = lnum + 1;
2931 spv->spv_checked_col = (p - nextline) + len
2932 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002933 }
2934
2935 // Turn index into actual attributes.
2936 if (spell_hlf != HLF_COUNT)
2937 spell_attr = highlight_attr[spell_hlf];
2938
Luuk van Baal30805a12023-05-27 22:22:10 +01002939 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002940 {
2941 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002942 && (p - nextline) + spv->spv_cap_col
2943 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002944 {
2945 // Remember that the word in the next line
2946 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002947 spv->spv_capcol_lnum = lnum + 1;
2948 spv->spv_cap_col = ((p - nextline)
2949 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 }
2951 else
2952 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002953 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002954 }
2955 }
2956 }
2957 if (spell_attr != 0)
2958 {
2959 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002960 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2961 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002962 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002963 wlv.char_attr = hl_combine_attr(spell_attr,
2964 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002965 }
2966#endif
2967#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002968 // we don't want linebreak to apply for lines that start with
2969 // leading spaces, followed by long letters (since it would add
2970 // a break at the beginning of a line and this might be unexpected)
2971 //
2972 // So only allow to linebreak, once we have found chars not in
2973 // 'breakat' in the line.
2974 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2975 !VIM_ISBREAK((int)*ptr))
2976 wlv.need_lbr = TRUE;
2977#endif
2978#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002979 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002980 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002981 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2982 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002983 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2984 : 0;
2985 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002986 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987
zeertzjqce53e3e2023-09-01 18:49:30 +02002988 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2989# ifdef FEAT_PROP_POPUP
2990 - vcol_first_char,
2991# endif
2992 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002993# ifdef FEAT_PROP_POPUP
2994 // do not want virtual text counted here
2995 cts.cts_has_prop_with_text = FALSE;
2996# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01002997 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002998 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02002999
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003000 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003001 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003002 // line break, but for TABs the highlighting should
3003 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003004 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003005
Bram Moolenaar1306b362022-08-06 15:59:06 +01003006 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003007# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003008 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003009 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003010 wp->w_buffer->b_p_vts_array) - 1;
3011# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003012 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003013 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003014# endif
3015
Bram Moolenaar1306b362022-08-06 15:59:06 +01003016 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3017 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003018# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003019 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003020 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003021# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003022 if (VIM_ISWHITE(c))
3023 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003024# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003025 if (c == TAB)
3026 // See "Tab alignment" below.
3027 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003028# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003029 if (!wp->w_p_list)
3030 c = ' ';
3031 }
3032 }
3033#endif
zeertzjqabc80812023-09-24 23:32:18 +02003034 if (wp->w_p_list)
3035 {
3036 in_multispace = c == ' ' && (*ptr == ' '
3037 || (prev_ptr > line && prev_ptr[-1] == ' '));
3038 if (!in_multispace)
3039 multispace_pos = 0;
3040 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003041
Bram Moolenaareed9d462021-02-15 20:38:25 +01003042 // 'list': Change char 160 to 'nbsp' and space to 'space'
3043 // setting in 'listchars'. But not when the character is
3044 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003045 if (wp->w_p_list
3046 && ((((c == 160 && mb_l == 1)
3047 || (mb_utf8
3048 && ((mb_c == 160 && mb_l == 2)
3049 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003050 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 || (c == ' '
3052 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003053 && (wp->w_lcs_chars.space
3054 || (in_multispace
3055 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003056 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 && ptr - line <= trailcol)))
3058 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003059 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3060 {
3061 c = wp->w_lcs_chars.multispace[multispace_pos++];
3062 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3063 multispace_pos = 0;
3064 }
3065 else
3066 c = (c == ' ') ? wp->w_lcs_chars.space
3067 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003068 if (area_attr == 0 && search_attr == 0)
3069 {
3070 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003071 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003072 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003073 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 }
3075 mb_c = c;
3076 if (enc_utf8 && utf_char2len(c) > 1)
3077 {
3078 mb_utf8 = TRUE;
3079 u8cc[0] = 0;
3080 c = 0xc0;
3081 }
3082 else
3083 mb_utf8 = FALSE;
3084 }
3085
zeertzjq2e7cba32022-06-10 15:30:32 +01003086 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3087 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003088 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003089 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3090 && wp->w_lcs_chars.leadmultispace != NULL)
3091 {
3092 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003093 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3094 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003095 multispace_pos = 0;
3096 }
3097
3098 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3099 c = wp->w_lcs_chars.trail;
3100
3101 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3102 c = wp->w_lcs_chars.lead;
3103
zeertzjq2e7cba32022-06-10 15:30:32 +01003104 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003105 c = wp->w_lcs_chars.space;
3106
3107
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003108 if (!attr_pri)
3109 {
3110 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003111 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003112 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003113 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 }
3115 mb_c = c;
3116 if (enc_utf8 && utf_char2len(c) > 1)
3117 {
3118 mb_utf8 = TRUE;
3119 u8cc[0] = 0;
3120 c = 0xc0;
3121 }
3122 else
3123 mb_utf8 = FALSE;
3124 }
3125 }
3126
3127 // Handling of non-printable characters.
3128 if (!vim_isprintc(c))
3129 {
3130 // when getting a character from the file, we may have to
3131 // turn it into something else on the way to putting it
3132 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003133 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003134 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003135 int tab_len = 0;
3136 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003137#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003138 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003139
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 // only adjust the tab_len, when at the first column
3141 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003142 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003143 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003144#endif
3145 // tab amount depends on current column
3146#ifdef FEAT_VARTABS
3147 tab_len = tabstop_padding(vcol_adjusted,
3148 wp->w_buffer->b_p_ts,
3149 wp->w_buffer->b_p_vts_array) - 1;
3150#else
3151 tab_len = (int)wp->w_buffer->b_p_ts
3152 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3153#endif
3154
3155#ifdef FEAT_LINEBREAK
3156 if (!wp->w_p_lbr || !wp->w_p_list)
3157#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003158 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003159 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003160 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003161 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003162#ifdef FEAT_LINEBREAK
3163 else
3164 {
3165 char_u *p;
3166 int len;
3167 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003168 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003169
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003170# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003171 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003172 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003173 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003174
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003176 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003177 && old_boguscols > 0
3178 && wlv.n_extra > tab_len)
3179 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003180# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003181 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003182 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003183 // If wlv.n_extra > 0, it gives the number of chars
3184 // to use for a tab, else we need to calculate the
3185 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003186 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3187 len = tab_len * tab2_len;
3188 if (wp->w_lcs_chars.tab3)
3189 len += mb_char2len(wp->w_lcs_chars.tab3)
3190 - tab2_len;
3191 if (wlv.n_extra > 0)
3192 len += wlv.n_extra - tab_len;
3193 c = wp->w_lcs_chars.tab1;
3194 p = alloc(len + 1);
3195 if (p == NULL)
3196 wlv.n_extra = 0;
3197 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003198 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003199 vim_memset(p, ' ', len);
3200 p[len] = NUL;
3201 vim_free(wlv.p_extra_free);
3202 wlv.p_extra_free = p;
3203 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003204 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003205 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003206
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003207 if (*p == NUL)
3208 {
3209 tab_len = i;
3210 break;
3211 }
3212
3213 // if tab3 is given, use it for the last
3214 // char
3215 if (wp->w_lcs_chars.tab3
3216 && i == tab_len - 1)
3217 lcs = wp->w_lcs_chars.tab3;
3218 p += mb_char2bytes(lcs, p);
3219 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003220 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003221 }
3222 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003223# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003224 // n_extra will be increased by
3225 // FIX_FOX_BOGUSCOLS macro below, so need to
3226 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003227 if (wlv.vcol_off_co > 0)
3228 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003229# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003230 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003231 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003232 }
3233#endif
3234#ifdef FEAT_CONCEAL
3235 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003236 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237
3238 // Tab alignment should be identical regardless of
3239 // 'conceallevel' value. So tab compensates of all
3240 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003241 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003242 // line. Note that the tab can be longer than
3243 // 'tabstop' when there are concealed characters.
3244 FIX_FOR_BOGUSCOLS;
3245
3246 // Make sure, the highlighting for the tab char will be
3247 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003248 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003249 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003250 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003251 tab_len += vc_saved;
3252 }
3253#endif
3254 mb_utf8 = FALSE; // don't draw as UTF-8
3255 if (wp->w_p_list)
3256 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003257 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003258 ? wp->w_lcs_chars.tab3
3259 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003260#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003261 if (wp->w_p_lbr && wlv.p_extra != NULL
3262 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003264 else
3265#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003266 wlv.c_extra = wp->w_lcs_chars.tab2;
3267 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003268 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003269 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003270 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003271 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003272 mb_c = c;
3273 if (enc_utf8 && utf_char2len(c) > 1)
3274 {
3275 mb_utf8 = TRUE;
3276 u8cc[0] = 0;
3277 c = 0xc0;
3278 }
3279 }
3280 else
3281 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003282 wlv.c_final = NUL;
3283 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003284 c = ' ';
3285 }
3286 }
3287 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003288 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003289 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003290 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3291 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003292 && VIsual_mode != Ctrl_V
3293 && (
3294# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003295 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003296# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003297 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 && !(noinvcur
3299 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003300 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003301 && lcs_eol_one > 0)
3302 {
3303 // Display a '$' after the line or highlight an extra
3304 // character if the line break is included.
3305#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3306 // For a diff line the highlighting continues after the
3307 // "$".
3308 if (
3309# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003310 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003311# ifdef LINE_ATTR
3312 &&
3313# endif
3314# endif
3315# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003316 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317# endif
3318 )
3319#endif
3320 {
3321 // In virtualedit, visual selections may extend
3322 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003323 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003324 && wlv.tocol != MAXCOL
3325 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003326 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003327 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003328 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003329 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3330 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003331 else
3332 c = ' ';
3333 lcs_eol_one = -1;
3334 --ptr; // put it back at the NUL
3335 if (!attr_pri)
3336 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003337 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003338 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003339 n_attr = 1;
3340 }
3341 mb_c = c;
3342 if (enc_utf8 && utf_char2len(c) > 1)
3343 {
3344 mb_utf8 = TRUE;
3345 u8cc[0] = 0;
3346 c = 0xc0;
3347 }
3348 else
3349 mb_utf8 = FALSE; // don't draw as UTF-8
3350 }
3351 else if (c != NUL)
3352 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003353 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3354 if (wlv.n_extra == 0)
3355 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003356#ifdef FEAT_RIGHTLEFT
3357 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003358 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003359#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003360 wlv.c_extra = NUL;
3361 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362#ifdef FEAT_LINEBREAK
3363 if (wp->w_p_lbr)
3364 {
3365 char_u *p;
3366
Bram Moolenaar1306b362022-08-06 15:59:06 +01003367 c = *wlv.p_extra;
3368 p = alloc(wlv.n_extra + 1);
3369 vim_memset(p, ' ', wlv.n_extra);
3370 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3371 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003372 vim_free(wlv.p_extra_free);
3373 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003374 }
3375 else
3376#endif
3377 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003378 wlv.n_extra = byte2cells(c) - 1;
3379 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 if (!attr_pri)
3382 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003383 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003384 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003385 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003386#ifdef FEAT_PROP_POPUP
3387 if (text_prop_type != NULL &&
3388 text_prop_flags & PT_FLAG_OVERRIDE)
3389 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3390#endif
3391
Bram Moolenaar1306b362022-08-06 15:59:06 +01003392 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003393 }
3394 mb_utf8 = FALSE; // don't draw as UTF-8
3395 }
3396 else if (VIsual_active
3397 && (VIsual_mode == Ctrl_V
3398 || VIsual_mode == 'v')
3399 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003400 && wlv.tocol != MAXCOL
3401 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003402 && (
3403#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003404 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003405#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003406 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003407 {
3408 c = ' ';
3409 --ptr; // put it back at the NUL
3410 }
3411#if defined(LINE_ATTR)
3412 else if ((
3413# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003414 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003415# endif
3416# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003417 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003418# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003419 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003420 ) && (
3421# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003422 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003423# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003424 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003425# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003426 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003427# endif
3428 < wp->w_width)))
3429 {
3430 // Highlight until the right side of the window
3431 c = ' ';
3432 --ptr; // put it back at the NUL
3433
3434 // Remember we do the char for line highlighting.
3435 ++did_line_attr;
3436
3437 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003438 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003439 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003440 || (wp->w_p_list &&
3441 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003442 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003443#ifdef FEAT_SIGNS
3444 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003445 // but not when cursorline is active
3446 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3447 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003448 wlv.char_attr = wlv.sattr.sat_linehl;
3449#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003450# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003451 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003452 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003453 wlv.diff_hlf = HLF_CHD;
3454 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003455 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003456 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003457 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3458 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003460 || (wlv.vcol >= left_curline_col
3461 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 wlv.char_attr = hl_combine_attr(
3463 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003464 }
3465 }
3466# endif
3467# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003468 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003469 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003470 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003471 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3472 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003473 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003474 if (!wlv.cul_screenline
3475 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003476 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003477 wlv.char_attr = hl_combine_attr(
3478 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003480 else if (wlv.line_attr)
3481 wlv.char_attr = hl_combine_attr(
3482 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003483 }
3484# endif
3485 }
3486#endif
3487 }
3488
3489#ifdef FEAT_CONCEAL
3490 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003491 && (wp != curwin || lnum != wp->w_cursor.lnum
3492 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003493 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3494 && !(lnum_in_visual_area
3495 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3496 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003497 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003498 if (((prev_syntax_id != syntax_seqnr
3499 && (syntax_flags & HL_CONCEAL) != 0)
3500 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003501 && (syn_get_sub_char() != NUL
3502 || (has_match_conc && match_conc)
3503 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003504 && wp->w_p_cole != 3)
3505 {
3506 // First time at this concealed item: display one
3507 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003508 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003509 c = match_conc;
3510 else if (syn_get_sub_char() != NUL)
3511 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003512 else if (wp->w_lcs_chars.conceal != NUL)
3513 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003514 else
3515 c = ' ';
3516
zeertzjq010e1532024-03-14 18:22:17 +01003517 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3518 // When the first char to be concealed is double-width,
3519 // need to advance one more virtual column.
3520 wlv.n_extra++;
3521
3522 mb_c = c;
3523 if (enc_utf8 && utf_char2len(c) > 1)
3524 {
3525 mb_utf8 = TRUE;
3526 u8cc[0] = 0;
3527 c = 0xc0;
3528 }
3529 else
3530 mb_utf8 = FALSE; // don't draw as UTF-8
3531
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003532 prev_syntax_id = syntax_seqnr;
3533
Bram Moolenaar1306b362022-08-06 15:59:06 +01003534 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003535 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003536 wlv.vcol += wlv.n_extra;
3537 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 {
3539# ifdef FEAT_RIGHTLEFT
3540 if (wp->w_p_rl)
3541 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003542 wlv.col -= wlv.n_extra;
3543 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 }
3545 else
3546# endif
3547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 wlv.boguscols += wlv.n_extra;
3549 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003552 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003553 n_attr = 0;
3554 }
zeertzjqb557f482023-08-22 22:07:34 +02003555 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 {
3557 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003558 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003560 }
3561 else
3562 {
3563 prev_syntax_id = 0;
3564 is_concealing = FALSE;
3565 }
3566
zeertzjqb557f482023-08-22 22:07:34 +02003567 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003568 // not showing the '>', put pointer back to avoid getting stuck
3569 ++ptr;
3570
3571#endif // FEAT_CONCEAL
3572 }
3573
3574#ifdef FEAT_CONCEAL
3575 // In the cursor line and we may be concealing characters: correct
3576 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003577 // With 'virtualedit' we may never reach cursor position, but we still
3578 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003579 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003580 && wp == curwin && lnum == wp->w_cursor.lnum
3581 && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003582 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003583 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003584# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003585 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003586 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003587 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003588# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003589 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003590 if (wlv.vcol + skip_cells < wp->w_virtcol)
3591 // Cursor beyond end of the line with 'virtualedit'.
3592 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003593 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003594 did_wcol = TRUE;
3595 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003596# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003597 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003598# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003599 }
3600#endif
3601
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003602 // Use "wlv.extra_attr", but don't override visual selection
3603 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003604 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3605 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003606 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003607 && (!attr_pri
3608#ifdef FEAT_PROP_POPUP
3609 || (text_prop_flags & PT_FLAG_OVERRIDE)
3610#endif
3611 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003612 {
3613#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003614 if (wlv.line_attr)
3615 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003616 else
3617#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003618 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003619#ifdef FEAT_PROP_POPUP
3620 if (reset_extra_attr)
3621 {
3622 reset_extra_attr = FALSE;
3623 wlv.extra_attr = 0;
3624 }
3625#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003626 }
3627
3628#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3629 // XIM don't send preedit_start and preedit_end, but they send
3630 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3631 // im_is_preediting() here.
3632 if (p_imst == IM_ON_THE_SPOT
3633 && xic != NULL
3634 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003635 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003636 && !p_imdisable
3637 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003638 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003639 {
3640 colnr_T tcol;
3641
3642 if (preedit_end_col == MAXCOL)
3643 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3644 else
3645 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003646 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003647 {
3648 if (feedback_old_attr < 0)
3649 {
3650 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003651 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003652 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003653 wlv.char_attr = im_get_feedback_attr(feedback_col);
3654 if (wlv.char_attr < 0)
3655 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003656 feedback_col++;
3657 }
3658 else if (feedback_old_attr >= 0)
3659 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003660 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003661 feedback_old_attr = -1;
3662 feedback_col = 0;
3663 }
3664 }
3665#endif
3666 // Handle the case where we are in column 0 but not on the first
3667 // character of the line and the user wants us to show us a
3668 // special character (via 'listchars' option "precedes:<char>".
3669 if (lcs_prec_todo != NUL
3670 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003671 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3672 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003673#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003674 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003675#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003676 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003677 && c != NUL)
3678 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003679 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003680 lcs_prec_todo = NUL;
3681 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3682 {
3683 // Double-width character being overwritten by the "precedes"
3684 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003685 wlv.c_extra = MB_FILLER_CHAR;
3686 wlv.c_final = NUL;
3687 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003688 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003689 wlv.extra_attr =
3690 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003691 }
3692 mb_c = c;
3693 if (enc_utf8 && utf_char2len(c) > 1)
3694 {
3695 mb_utf8 = TRUE;
3696 u8cc[0] = 0;
3697 c = 0xc0;
3698 }
3699 else
3700 mb_utf8 = FALSE; // don't draw as UTF-8
3701 if (!attr_pri)
3702 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003703 saved_attr3 = wlv.char_attr; // save current attr
3704 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003705 n_attr3 = 1;
3706 }
3707 }
3708
3709 // At end of the text line or just after the last character.
3710 if ((c == NUL
3711#if defined(LINE_ATTR)
3712 || did_line_attr == 1
3713#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003714 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003715 {
3716#ifdef FEAT_SEARCH_EXTRA
3717 // flag to indicate whether prevcol equals startcol of search_hl or
3718 // one of the matches
3719 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3720 (long)(ptr - line) - (c == NUL));
3721#endif
3722 // Invert at least one char, used for Visual and empty line or
3723 // highlight match at end of line. If it's beyond the last
3724 // char on the screen, just overwrite that one (tricky!) Not
3725 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003726 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003727 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003728 && (VIsual_mode != Ctrl_V
3729 || lnum == VIsual.lnum
3730 || lnum == curwin->w_cursor.lnum)
3731 && c == NUL)
3732#ifdef FEAT_SEARCH_EXTRA
3733 // highlight 'hlsearch' match at end of line
3734 || (prevcol_hl_flag
3735# ifdef FEAT_SYN_HL
3736 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3737 && !(wp == curwin && VIsual_active))
3738# endif
3739# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003740 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003741# endif
3742# if defined(LINE_ATTR)
3743 && did_line_attr <= 1
3744# endif
3745 )
3746#endif
3747 ))
3748 {
3749 int n = 0;
3750
3751#ifdef FEAT_RIGHTLEFT
3752 if (wp->w_p_rl)
3753 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003754 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003755 n = 1;
3756 }
3757 else
3758#endif
3759 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 n = -1;
3762 }
3763 if (n != 0)
3764 {
3765 // At the window boundary, highlight the last character
3766 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003767 wlv.off += n;
3768 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003769 }
3770 else
3771 {
3772 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003774 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003775 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003776 }
3777#ifdef FEAT_SEARCH_EXTRA
3778 if (area_attr == 0)
3779 {
3780 // Use attributes from match with highest priority among
3781 // 'search_hl' and the match list.
3782 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003783 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003784 }
3785#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003786 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003787 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003788#ifdef FEAT_RIGHTLEFT
3789 if (wp->w_p_rl)
3790 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003791 --wlv.col;
3792 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003793 }
3794 else
3795#endif
3796 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 ++wlv.col;
3798 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003800 ++wlv.vcol;
3801 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003802 }
3803 }
3804
3805 // At end of the text line.
3806 if (c == NUL)
3807 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003808#ifdef FEAT_PROP_POPUP
3809 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003810 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003811 // Put the pointer back to the NUL.
3812 --ptr;
3813 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003814 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003815 else
3816#endif
3817 {
3818 draw_screen_line(wp, &wlv);
3819
3820 // Update w_cline_height and w_cline_folded if the cursor line
3821 // was updated (saves a call to plines() later).
3822 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3823 {
3824 curwin->w_cline_row = startrow;
3825 curwin->w_cline_height = wlv.row - startrow;
3826#ifdef FEAT_FOLDING
3827 curwin->w_cline_folded = FALSE;
3828#endif
3829 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3830 }
3831 break;
3832 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003833 }
3834
3835 // Show "extends" character from 'listchars' if beyond the line end and
3836 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003837 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003838 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 && wp->w_p_list
3840 && !wp->w_p_wrap
3841#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003842 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003843#endif
3844 && (
3845#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003846 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003847#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003848 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003850 || lcs_eol_one > 0
3851 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003852 || *wlv.p_extra != NUL))
3853#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003854 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003855#endif
3856 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003857 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003858 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003859 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003860 mb_c = c;
3861 if (enc_utf8 && utf_char2len(c) > 1)
3862 {
3863 mb_utf8 = TRUE;
3864 u8cc[0] = 0;
3865 c = 0xc0;
3866 }
3867 else
3868 mb_utf8 = FALSE;
3869 }
3870
3871#ifdef FEAT_SYN_HL
3872 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003873 if (wlv.draw_color_col)
3874 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003875
3876 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3877 // highlight the cursor position itself.
3878 // Also highlight the 'colorcolumn' if it is different than
3879 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003880 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3881 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003882 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003883 if (((wlv.draw_state == WL_LINE
3884 || wlv.draw_state == WL_BRI
3885 || wlv.draw_state == WL_SBR)
3886 && !lnum_in_visual_area
3887 && search_attr == 0
3888 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003889# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003890 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003891# endif
3892 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003893 {
3894 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3895 && lnum != wp->w_cursor.lnum)
3896 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003897 vcol_save_attr = wlv.char_attr;
3898 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3899 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003900 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003901 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003903 vcol_save_attr = wlv.char_attr;
3904 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003905 }
3906 }
3907#endif
3908
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003909 if (wlv.draw_state == WL_LINE)
3910 vcol_prev = wlv.vcol;
3911
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003912 // Store character to be displayed.
3913 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003914 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003915 {
3916 // Store the character.
3917#if defined(FEAT_RIGHTLEFT)
3918 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3919 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003920 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003921 --wlv.off;
3922 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003923 }
3924#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003925 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003926 if (enc_dbcs == DBCS_JPNU)
3927 {
3928 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003929 ScreenLines[wlv.off] = 0x8e;
3930 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003931 }
3932 else if (enc_utf8)
3933 {
3934 if (mb_utf8)
3935 {
3936 int i;
3937
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003938 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003939 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003940 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003941 for (i = 0; i < Screen_mco; ++i)
3942 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003943 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003944 if (u8cc[i] == 0)
3945 break;
3946 }
3947 }
3948 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003949 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950 }
3951 if (multi_attr)
3952 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003953 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003954 multi_attr = 0;
3955 }
3956 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003957 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003958
zeertzjqdb54e982023-09-21 16:33:09 +02003959 if (wlv.draw_state > WL_NR
3960#ifdef FEAT_DIFF
3961 && wlv.filler_todo <= 0
3962#endif
3963 )
3964 ScreenCols[wlv.off] = wlv.vcol;
3965 else
3966 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003967
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003968 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3969 {
3970 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003971 ++wlv.off;
3972 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003973 if (enc_utf8)
3974 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003975 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003976 else
3977 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003978 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003979
Bram Moolenaar1306b362022-08-06 15:59:06 +01003980 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003981#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003982 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003983#endif
3984 )
zeertzjqdb54e982023-09-21 16:33:09 +02003985 ScreenCols[wlv.off] = ++wlv.vcol;
3986 else
3987 ScreenCols[wlv.off] = -1;
3988
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003989 // When "wlv.tocol" is halfway a character, set it to the end
3990 // of the character, otherwise highlighting won't stop.
3991 if (wlv.tocol == wlv.vcol)
3992 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003993
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003994#ifdef FEAT_RIGHTLEFT
3995 if (wp->w_p_rl)
3996 {
3997 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003998 --wlv.off;
3999 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000 }
4001#endif
4002 }
4003#ifdef FEAT_RIGHTLEFT
4004 if (wp->w_p_rl)
4005 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004006 --wlv.off;
4007 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004008 }
4009 else
4010#endif
4011 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004012 ++wlv.off;
4013 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004014 }
4015 }
4016#ifdef FEAT_CONCEAL
4017 else if (wp->w_p_cole > 0 && is_concealing)
4018 {
zeertzjq010e1532024-03-14 18:22:17 +01004019 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4020
zeertzjqb557f482023-08-22 22:07:34 +02004021 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004022 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004023 if (concealed_wide)
4024 {
4025 // When a double-width char is concealed,
4026 // need to advance one more virtual column.
4027 ++wlv.vcol;
4028 ++wlv.vcol_off_co;
4029 }
4030
Bram Moolenaar1306b362022-08-06 15:59:06 +01004031 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004032 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004033
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004034 if (wp->w_p_wrap)
4035 {
4036 // Special voodoo required if 'wrap' is on.
4037 //
4038 // Advance the column indicator to force the line
4039 // drawing to wrap early. This will make the line
4040 // take up the same screen space when parts are concealed,
4041 // so that cursor line computations aren't messed up.
4042 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004043 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004044 // trailing junk to be written out of the screen line
4045 // we are building, 'boguscols' keeps track of the number
4046 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004047 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004048 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004049 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050# ifdef FEAT_RIGHTLEFT
4051 if (wp->w_p_rl)
4052 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004053 wlv.col -= wlv.n_extra;
4054 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004055 }
4056 else
4057# endif
4058 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004059 wlv.col += wlv.n_extra;
4060 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004061 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004062 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004063 n_attr = 0;
4064 }
4065
zeertzjq010e1532024-03-14 18:22:17 +01004066 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004067 {
4068 // Need to fill two screen columns.
4069# ifdef FEAT_RIGHTLEFT
4070 if (wp->w_p_rl)
4071 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004072 --wlv.boguscols;
4073 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004074 }
4075 else
4076# endif
4077 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 ++wlv.boguscols;
4079 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080 }
4081 }
4082
4083# ifdef FEAT_RIGHTLEFT
4084 if (wp->w_p_rl)
4085 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004086 --wlv.boguscols;
4087 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004088 }
4089 else
4090# endif
4091 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004092 ++wlv.boguscols;
4093 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094 }
4095 }
4096 else
4097 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004098 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004099 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004100 wlv.vcol += wlv.n_extra;
4101 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004102 n_attr = 0;
4103 }
4104 }
4105
4106 }
4107#endif // FEAT_CONCEAL
4108 else
zeertzjqb557f482023-08-22 22:07:34 +02004109 --skip_cells;
4110
4111 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4112 {
4113 wlv.vcol += skipped_cells;
4114 skipped_cells = 0;
4115 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004116
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004117 // Only advance the "wlv.vcol" when after the 'number' or
4118 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004119 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004120#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004121 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122#endif
4123 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004124 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004125
4126#ifdef FEAT_SYN_HL
4127 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004128 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004129#endif
4130
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004131 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004132 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4133 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004134
4135 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004136 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004137 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004138 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004139 if (wlv.n_attr_skip > 0)
4140 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004141
4142 // At end of screen line and there is more to come: Display the line
4143 // so far. If there is no more to display it is caught above.
4144 if ((
4145#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004146 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004148 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004149 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004150 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004151#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004152 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004154#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004155 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004156 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004157#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004158 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004159 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004160 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4161 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004162 )
4163 {
4164#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004165 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004166 // Apply 'cursorline' and 'wincolor' highlight.
4167 if (wlv.boguscols != 0 && (
4168# ifdef LINE_ATTR
4169 wlv.line_attr != 0 ||
4170# endif
4171 wlv.win_attr != 0
4172 )
4173 )
4174 {
4175 int attr = wlv.win_attr;
4176# ifdef LINE_ATTR
4177 if (wlv.line_attr != 0)
4178 attr = hl_combine_attr(attr, wlv.line_attr);
4179# endif
4180 while ((
4181# ifdef FEAT_RIGHTLEFT
4182 wp->w_p_rl ? wlv.col >= 0 :
4183# endif
4184 wlv.col < wp->w_width))
4185 {
4186 ScreenLines[wlv.off] = ' ';
4187 if (enc_utf8)
4188 ScreenLinesUC[wlv.off] = 0;
4189 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004190 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004191# ifdef FEAT_RIGHTLEFT
4192 if (wp->w_p_rl)
4193 {
4194 wlv.off--;
4195 wlv.col--;
4196 wlv.boguscols++;
4197 }
4198 else
4199# endif
4200 {
4201 wlv.off++;
4202 wlv.col++;
4203 wlv.boguscols--;
4204 }
4205 }
4206 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004207 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004208 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004209 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004210 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004211#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004212 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004213#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004214 ++wlv.row;
4215 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004216
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004217 // When not wrapping and finished diff lines, break here.
4218 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004220 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004221#endif
4222#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004223 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004224 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004225#endif
4226 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004227 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004228#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004229 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004230 {
4231 // do not output more of the line, only the "below" prop
4232 ptr += STRLEN(ptr);
4233# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004234 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004235# endif
4236 }
4237#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004238
4239 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004240 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004241#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004242 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004243#endif
4244 )
4245 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004246 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4247 draw_vsep_win(wp, wlv.row);
4248 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004249 }
4250
4251 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004252 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004253 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004254 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004255 break;
4256 }
4257
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004258 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004259#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004260 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004261#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004262#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004263 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004264#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004265 && wp->w_width == Columns)
4266 {
4267 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004268 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004269
4270 // Special trick to make copy/paste of wrapped lines work with
4271 // xterm/screen: write an extra character beyond the end of
4272 // the line. This will work with all terminal types
4273 // (regardless of the xn,am settings).
4274 // Only do this on a fast tty.
4275 // Only do this if the cursor is on the current line
4276 // (something has been written in it).
4277 // Don't do this for the GUI.
4278 // Don't do this for double-width characters.
4279 // Don't do this for a window not at the right screen border.
4280 if (p_tf
4281#ifdef FEAT_GUI
4282 && !gui.in_use
4283#endif
4284 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004285 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4286 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004287 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004288 || (*mb_off2cells)(
4289 LineOffset[wlv.screen_row - 1]
4290 + (int)Columns - 2,
4291 LineOffset[wlv.screen_row]
4292 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004293 {
4294 // First make sure we are at the end of the screen line,
4295 // then output the same character again to let the
4296 // terminal know about the wrap. If the terminal doesn't
4297 // auto-wrap, we overwrite the character.
4298 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004299 screen_char(LineOffset[wlv.screen_row - 1]
4300 + (unsigned)Columns - 1,
4301 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004302
4303 // When there is a multi-byte character, just output a
4304 // space to keep it simple.
4305 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004306 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004307 out_char(' ');
4308 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004309 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004310 + (Columns - 1)]);
4311 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004312 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004313 screen_start(); // don't know where cursor is now
4314 }
4315 }
4316
Bram Moolenaar1306b362022-08-06 15:59:06 +01004317 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004318
Bram Moolenaareed9d462021-02-15 20:38:25 +01004319 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004320#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004321 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004322# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004323 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004324# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004325 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004326 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004327#endif
4328#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004329 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004330 // When the filler lines are actually below the last line of the
4331 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004332 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004333 break;
4334#endif
4335 }
4336
4337 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004338#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004339 vim_free(text_props);
4340 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004341 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004342#endif
4343
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004344 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004345 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004346 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004347}