blob: a8de449af4e837c23a1ac4dde846afe89b20e457 [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 Moolenaar9d9a20e2023-02-11 13:49:01 +00002075 int display_text_first = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002076
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002077 // Add any text property that starts in this column.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002078 // With 'nowrap' and not in the first screen line only "below"
2079 // text prop can show.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002080 while (text_prop_next < text_prop_count
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002081 && (text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002082 ? ((*ptr == NUL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002083 && (wp->w_p_wrap
2084 || wlv.row == startrow
2085 || (text_props[text_prop_next].tp_flags
2086 & TP_FLAG_ALIGN_BELOW)))
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002087 || (bcol == 0
2088 && (text_props[text_prop_next].tp_flags
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002089 & TP_FLAG_ALIGN_ABOVE)))
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002090 : bcol >= text_props[text_prop_next].tp_col - 1))
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002091 {
Bram Moolenaar9113c2c2022-08-13 20:17:34 +01002092 if (text_props[text_prop_next].tp_col == MAXCOL
2093 || bcol <= text_props[text_prop_next].tp_col - 1
Bram Moolenaarf3fa1842021-02-10 17:20:28 +01002094 + text_props[text_prop_next].tp_len)
2095 text_prop_idxs[text_props_active++] = text_prop_next;
2096 ++text_prop_next;
2097 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002098
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002099 if (wlv.n_extra == 0 ||
2100 (!wlv.extra_for_textprop
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002101 && !(text_prop_type != NULL &&
2102 text_prop_flags & PT_FLAG_OVERRIDE)
Christian Brabandtdbeadf02023-08-19 15:35:04 +02002103 ))
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002104 {
2105 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002106 text_prop_attr_comb = 0;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002107 text_prop_flags = 0;
2108 text_prop_type = NULL;
2109 text_prop_id = 0;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002110 reset_extra_attr = FALSE;
Bram Moolenaar9e7e28f2022-08-14 16:36:38 +01002111 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002112 if (text_props_active > 0 && wlv.n_extra == 0
2113 && !display_text_first)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002114 {
Bram Moolenaarbe3dbda2022-07-26 11:42:34 +01002115 int used_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002116 int used_attr = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002117 int other_tpi = -1;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002118
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002119 text_prop_above = FALSE;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002120 text_prop_follows = FALSE;
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002121
2122 // Sort the properties on priority and/or starting last.
2123 // Then combine the attributes, highest priority last.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002124 sort_text_props(wp->w_buffer, text_props,
2125 text_prop_idxs, text_props_active);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002126
2127 for (pi = 0; pi < text_props_active; ++pi)
2128 {
2129 int tpi = text_prop_idxs[pi];
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002130 textprop_T *tp = &text_props[tpi];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002131 proptype_T *pt = text_prop_type_by_id(
Bram Moolenaarcd105412022-10-10 19:50:42 +01002132 wp->w_buffer, tp->tp_type);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002133
Bram Moolenaarcd105412022-10-10 19:50:42 +01002134 // Only use a text property that can be displayed.
2135 // Skip "after" properties when wrap is off and at the
2136 // end of the window.
2137 if (pt != NULL
2138 && (pt->pt_hl_id > 0 || tp->tp_id < 0)
2139 && tp->tp_id != -MAXCOL
2140 && !(tp->tp_id < 0
2141 && !wp->w_p_wrap
2142 && (tp->tp_flags & (TP_FLAG_ALIGN_RIGHT
2143 | TP_FLAG_ALIGN_ABOVE
2144 | TP_FLAG_ALIGN_BELOW)) == 0
2145 && wlv.col >= wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002146 {
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002147 if (tp->tp_col == MAXCOL
2148 && *ptr == NUL
2149 && ((wp->w_p_list && lcs_eol_one > 0
2150 && (tp->tp_flags
2151 & TP_FLAG_ALIGN_ABOVE) == 0)
2152 || (ptr == line
2153 && !did_line
2154 && (tp->tp_flags
2155 & TP_FLAG_ALIGN_BELOW))))
2156 {
2157 // skip this prop, first display the '$' after
2158 // the line or display an empty line
2159 text_prop_follows = TRUE;
2160 if (used_tpi < 0)
2161 display_text_first = TRUE;
2162 continue;
2163 }
2164
Bram Moolenaar87f3a2c2022-08-10 20:50:23 +01002165 if (pt->pt_hl_id > 0)
2166 used_attr = syn_id2attr(pt->pt_hl_id);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002167 text_prop_type = pt;
2168 text_prop_attr =
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002169 hl_combine_attr(text_prop_attr, used_attr);
Bram Moolenaar51b2fc22023-01-21 15:54:59 +00002170 if (used_tpi >= 0 && text_props[used_tpi].tp_id < 0)
2171 other_tpi = used_tpi;
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002172 text_prop_flags = pt->pt_flags;
2173 text_prop_id = tp->tp_id;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002174 used_tpi = tpi;
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00002175 display_text_first = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002176 }
2177 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002178 if (text_prop_id < 0 && used_tpi >= 0
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002179 && -text_prop_id
2180 <= wp->w_buffer->b_textprop_text.ga_len)
2181 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002182 textprop_T *tp = &text_props[used_tpi];
2183 char_u *p = ((char_u **)wp->w_buffer
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002184 ->b_textprop_text.ga_data)[
2185 -text_prop_id - 1];
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002186 int above = (tp->tp_flags
2187 & TP_FLAG_ALIGN_ABOVE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002188 int bail_out = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002189
2190 // reset the ID in the copy to avoid it being used
2191 // again
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002192 tp->tp_id = -MAXCOL;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002193
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002194 if (p != NULL)
2195 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002196 int right = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002197 & TP_FLAG_ALIGN_RIGHT);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002198 int below = (tp->tp_flags
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002199 & TP_FLAG_ALIGN_BELOW);
zeertzjq3c3cf1d2023-09-02 21:55:00 +02002200 int wrap = tp->tp_col < MAXCOL
2201 || (tp->tp_flags & TP_FLAG_WRAP);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002202 int padding = tp->tp_col == MAXCOL
2203 && tp->tp_len > 1
2204 ? tp->tp_len - 1 : 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002205
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002206 // Insert virtual text before the current
2207 // character, or add after the end of the line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002208 wlv.p_extra = p;
2209 wlv.c_extra = NUL;
2210 wlv.c_final = NUL;
2211 wlv.n_extra = (int)STRLEN(p);
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002212 wlv.extra_for_textprop = TRUE;
zeertzjq6e940d92023-08-17 23:21:40 +02002213 wlv.start_extra_for_textprop = TRUE;
Bram Moolenaaree28c702022-11-17 14:56:00 +00002214 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
2215 used_attr);
Bram Moolenaar09ff4b52022-08-01 16:51:02 +01002216 n_attr = mb_charlen(p);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002217 text_prop_attr = 0;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002218 text_prop_attr_comb = 0;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002219 if (*ptr == NUL)
2220 // don't combine char attr after EOL
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002221 text_prop_flags &= ~PT_FLAG_COMBINE;
zeertzjq6b9c2022023-09-11 20:01:17 +02002222# ifdef FEAT_LINEBREAK
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002223 if (above || below || right || !wrap)
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002224 {
2225 // no 'showbreak' before "below" text property
Bram Moolenaar04e0ed12022-09-10 20:00:56 +01002226 // or after "above" or "right" text property
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002227 wlv.need_showbreak = FALSE;
2228 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01002229 }
zeertzjq6b9c2022023-09-11 20:01:17 +02002230# endif
Bram Moolenaar79f8b842022-09-11 13:31:01 +01002231 if ((right || above || below || !wrap
2232 || padding > 0) && wp->w_width > 2)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002233 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002234 char_u *prev_p_extra = wlv.p_extra;
2235 int start_line;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002236
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002237 // Take care of padding, right-align and
2238 // truncation.
2239 // Shared with win_lbr_chartabsize(), must do
2240 // exactly the same.
2241 start_line = text_prop_position(wp, tp,
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002242 wlv.vcol,
zeertzjq6b9c2022023-09-11 20:01:17 +02002243# ifdef FEAT_RIGHTLEFT
2244 wp->w_p_rl
2245 ? wp->w_width - wlv.col - 1
2246 :
2247# endif
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002248 wlv.col,
2249 &wlv.n_extra, &wlv.p_extra,
Bram Moolenaar56a40fe2022-12-06 14:17:57 +00002250 &n_attr, &wlv.n_attr_skip,
2251 skip_cells > 0);
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002252 if (wlv.p_extra != prev_p_extra)
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002253 {
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002254 // wlv.p_extra was allocated
2255 vim_free(p_extra_free2);
2256 p_extra_free2 = wlv.p_extra;
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002257 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002258
Bram Moolenaarf53e0652023-02-19 14:16:02 +00002259 if (above)
2260 wlv.vcol_off_tp = wlv.n_extra;
2261
Bram Moolenaar02edfaa2022-11-18 23:13:47 +00002262 if (lcs_eol_one < 0
2263 && wp->w_p_wrap
2264 && wlv.col
Bram Moolenaara4abe512022-09-15 19:44:09 +01002265 + wlv.n_extra - 2 > wp->w_width)
2266 // don't bail out at end of line
Bram Moolenaara9a36482022-10-11 16:47:22 +01002267 text_prop_follows = TRUE;
Bram Moolenaara4abe512022-09-15 19:44:09 +01002268
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002269 // When 'wrap' is off then for "below" we need
dundargocc57b5bc2022-11-02 13:30:51 +00002270 // to start a new line explicitly.
Bram Moolenaarf396ce82022-08-23 18:39:37 +01002271 if (start_line)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002272 {
2273 draw_screen_line(wp, &wlv);
2274
2275 // When line got too long for screen break
2276 // here.
2277 if (wlv.row == endrow)
2278 {
2279 ++wlv.row;
2280 break;
2281 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002282 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar1206c162022-10-10 15:40:04 +01002283 bail_out = TRUE;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002284 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002285 }
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002286 }
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002287
Bram Moolenaarcd105412022-10-10 19:50:42 +01002288 // If the text didn't reach until the first window
2289 // column we need to skip cells.
2290 if (skip_cells > 0)
2291 {
2292 if (wlv.n_extra > skip_cells)
2293 {
2294 wlv.n_extra -= skip_cells;
2295 wlv.p_extra += skip_cells;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002296 wlv.n_attr_skip -= skip_cells;
2297 if (wlv.n_attr_skip < 0)
2298 wlv.n_attr_skip = 0;
zeertzjqb557f482023-08-22 22:07:34 +02002299 skipped_cells += skip_cells;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002300 skip_cells = 0;
2301 }
2302 else
2303 {
2304 // the whole text is left of the window, drop
2305 // it and advance to the next one
2306 skip_cells -= wlv.n_extra;
zeertzjqb557f482023-08-22 22:07:34 +02002307 skipped_cells += wlv.n_extra;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002308 wlv.n_extra = 0;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00002309 wlv.n_attr_skip = 0;
Bram Moolenaarcd105412022-10-10 19:50:42 +01002310 bail_out = TRUE;
2311 }
2312 }
2313
Bram Moolenaarb7963df2022-07-31 17:12:43 +01002314 // If another text prop follows the condition below at
2315 // the last window column must know.
Dylan Thacker-Smith83925be2024-02-21 21:03:10 +01002316 // If this is an "above" text prop and 'nowrap' then we
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01002317 // must wrap anyway.
2318 text_prop_above = above;
Bram Moolenaara9a36482022-10-11 16:47:22 +01002319 text_prop_follows |= other_tpi != -1
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002320 && (wp->w_p_wrap
2321 || (text_props[other_tpi].tp_flags
Bram Moolenaarf167c7b2022-10-09 21:53:58 +01002322 & (TP_FLAG_ALIGN_BELOW | TP_FLAG_ALIGN_RIGHT)));
Bram Moolenaar1206c162022-10-10 15:40:04 +01002323
2324 if (bail_out)
2325 // starting a new line for "below"
2326 continue;
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002327 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002328 }
Bram Moolenaar398649e2022-08-04 15:03:48 +01002329 else if (text_prop_next < text_prop_count
2330 && text_props[text_prop_next].tp_col == MAXCOL
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002331 && ((*ptr != NUL && ptr[mb_ptr2len(ptr)] == NUL)
2332 || (!wp->w_p_wrap
2333 && wlv.col == wp->w_width - 1
2334 && (text_props[text_prop_next].tp_flags
2335 & TP_FLAG_ALIGN_BELOW))))
Bram Moolenaar398649e2022-08-04 15:03:48 +01002336 // When at last-but-one character and a text property
2337 // follows after it, we may need to flush the line after
2338 // displaying that character.
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01002339 // Or when not wrapping and at the rightmost column.
Bram Moolenaar398649e2022-08-04 15:03:48 +01002340 text_prop_follows = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002341 }
zeertzjq6e940d92023-08-17 23:21:40 +02002342
2343 if (wlv.start_extra_for_textprop)
2344 {
2345 wlv.start_extra_for_textprop = FALSE;
2346 // restore search_attr and area_attr when n_extra
2347 // is down to zero
2348 saved_search_attr = search_attr;
2349 saved_area_attr = area_attr;
2350 search_attr = 0;
2351 area_attr = 0;
2352 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002353#endif
2354
zeertzjq6e940d92023-08-17 23:21:40 +02002355 int *area_attr_p =
2356#ifdef FEAT_PROP_POPUP
2357 wlv.extra_for_textprop ? &saved_area_attr :
2358#endif
2359 &area_attr;
2360
2361 // handle Visual or match highlighting in this line
2362 if (wlv.vcol == wlv.fromcol
2363 || (has_mbyte && wlv.vcol + 1 == wlv.fromcol
2364 && ((wlv.n_extra == 0 && (*mb_ptr2cells)(ptr) > 1)
2365 || (wlv.n_extra > 0 && wlv.p_extra != NULL
2366 && (*mb_ptr2cells)(wlv.p_extra) > 1)))
2367 || ((int)vcol_prev == fromcol_prev
2368 && vcol_prev < wlv.vcol // not at margin
2369 && wlv.vcol < wlv.tocol))
2370 *area_attr_p = vi_attr; // start highlighting
2371 else if (*area_attr_p != 0
2372 && (wlv.vcol == wlv.tocol
2373 || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
2374 *area_attr_p = 0; // stop highlighting
2375
zeertzjqe500ae82023-08-17 22:35:26 +02002376#ifdef FEAT_SEARCH_EXTRA
Bram Moolenaare38fc862022-08-11 17:24:50 +01002377 if (wlv.n_extra == 0)
2378 {
2379 // Check for start/end of 'hlsearch' and other matches.
2380 // After end, check for start/end of next match.
2381 // When another match, have to check for start again.
2382 v = (long)(ptr - line);
2383 search_attr = update_search_hl(wp, lnum, (colnr_T)v, &line,
2384 &screen_search_hl, &has_match_conc,
2385 &match_conc, did_line_attr, lcs_eol_one,
2386 &on_last_col);
2387 ptr = line + v; // "line" may have been changed
Bram Moolenaare38fc862022-08-11 17:24:50 +01002388
2389 // Do not allow a conceal over EOL otherwise EOL will be missed
2390 // and bad things happen.
2391 if (*ptr == NUL)
2392 has_match_conc = 0;
zeertzjqb25dbb32023-08-13 18:11:05 +02002393 }
zeertzjqe500ae82023-08-17 22:35:26 +02002394#endif
zeertzjqb25dbb32023-08-13 18:11:05 +02002395
Bram Moolenaare38fc862022-08-11 17:24:50 +01002396#ifdef FEAT_DIFF
2397 if (wlv.diff_hlf != (hlf_T)0)
2398 {
Bram Moolenaard097af72022-12-17 11:33:00 +00002399 // When there is extra text (e.g. virtual text) it gets the
2400 // diff highlighting for the line, but not for changed text.
Bram Moolenaare38fc862022-08-11 17:24:50 +01002401 if (wlv.diff_hlf == HLF_CHD && ptr - line >= change_start
2402 && wlv.n_extra == 0)
2403 wlv.diff_hlf = HLF_TXD; // changed text
Bram Moolenaar417e88b2022-12-17 15:03:02 +00002404 if (wlv.diff_hlf == HLF_TXD
2405 && ((ptr - line > change_end && wlv.n_extra == 0)
2406 || (wlv.n_extra > 0 && wlv.extra_for_textprop)))
Bram Moolenaare38fc862022-08-11 17:24:50 +01002407 wlv.diff_hlf = HLF_CHD; // changed line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002408 wlv.line_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaare38fc862022-08-11 17:24:50 +01002409 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
2410 && wp->w_p_culopt_flags != CULOPT_NBR
2411 && (!wlv.cul_screenline || (wlv.vcol >= left_curline_col
2412 && wlv.vcol <= right_curline_col)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002413 wlv.line_attr = hl_combine_attr(
2414 wlv.line_attr, HL_ATTR(HLF_CUL));
Bram Moolenaare38fc862022-08-11 17:24:50 +01002415 }
2416#endif
2417
Bram Moolenaara74fda62019-10-19 17:38:03 +02002418#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002419 if (extra_check && wlv.n_extra == 0)
Bram Moolenaar34390282019-10-16 14:38:26 +02002420 {
Bram Moolenaar82260af2019-10-20 13:16:22 +02002421 syntax_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002422# ifdef FEAT_TERMINAL
Bram Moolenaar34390282019-10-16 14:38:26 +02002423 if (get_term_attr)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002424 syntax_attr = term_get_attr(wp, lnum, wlv.vcol);
Bram Moolenaara74fda62019-10-19 17:38:03 +02002425# endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002426 // Get syntax attribute.
2427 if (has_syntax)
2428 {
2429 // Get the syntax attribute for the character. If there
2430 // is an error, disable syntax highlighting.
2431 save_did_emsg = did_emsg;
2432 did_emsg = FALSE;
2433
2434 v = (long)(ptr - line);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002435 if (v == prev_syntax_col)
2436 // at same column again
2437 syntax_attr = prev_syntax_attr;
2438 else
2439 {
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002440# ifdef FEAT_SPELL
Bram Moolenaar9115c612019-10-16 16:57:06 +02002441 can_spell = TRUE;
Bram Moolenaarb2fe1d62019-10-16 21:33:40 +02002442# endif
Bram Moolenaar9115c612019-10-16 16:57:06 +02002443 syntax_attr = get_syntax_attr((colnr_T)v,
Bram Moolenaar34390282019-10-16 14:38:26 +02002444# ifdef FEAT_SPELL
Luuk van Baal30805a12023-05-27 22:22:10 +01002445 spv->spv_has_spell ? &can_spell :
Bram Moolenaar34390282019-10-16 14:38:26 +02002446# endif
Luuk van Baal30805a12023-05-27 22:22:10 +01002447 NULL, FALSE);
Bram Moolenaar9115c612019-10-16 16:57:06 +02002448 prev_syntax_col = v;
2449 prev_syntax_attr = syntax_attr;
2450 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002451
Bram Moolenaar34390282019-10-16 14:38:26 +02002452 if (did_emsg)
2453 {
2454 wp->w_s->b_syn_error = TRUE;
2455 has_syntax = FALSE;
2456 syntax_attr = 0;
2457 }
2458 else
2459 did_emsg = save_did_emsg;
2460# ifdef SYN_TIME_LIMIT
2461 if (wp->w_s->b_syn_slow)
2462 has_syntax = FALSE;
2463# endif
2464
2465 // Need to get the line again, a multi-line regexp may
2466 // have made it invalid.
2467 line = ml_get_buf(wp->w_buffer, lnum, FALSE);
2468 ptr = line + v;
2469# ifdef FEAT_CONCEAL
2470 // no concealing past the end of the line, it interferes
2471 // with line highlighting
2472 if (*ptr == NUL)
2473 syntax_flags = 0;
2474 else
2475 syntax_flags = get_syntax_info(&syntax_seqnr);
2476# endif
2477 }
Bram Moolenaar34390282019-10-16 14:38:26 +02002478 }
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01002479# ifdef FEAT_PROP_POPUP
Bram Moolenaardbd43162019-11-09 21:28:14 +01002480 // Combine text property highlight into syntax highlight.
2481 if (text_prop_type != NULL)
2482 {
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002483 if (text_prop_flags & PT_FLAG_COMBINE)
Bram Moolenaardbd43162019-11-09 21:28:14 +01002484 syntax_attr = hl_combine_attr(syntax_attr, text_prop_attr);
2485 else
2486 syntax_attr = text_prop_attr;
Bram Moolenaarcf2bb632022-09-02 13:26:29 +01002487 text_prop_attr_comb = syntax_attr;
Bram Moolenaardbd43162019-11-09 21:28:14 +01002488 }
2489# endif
Bram Moolenaara74fda62019-10-19 17:38:03 +02002490#endif
Bram Moolenaar34390282019-10-16 14:38:26 +02002491
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002492 // Decide which of the highlight attributes to use.
2493 attr_pri = TRUE;
2494#ifdef LINE_ATTR
2495 if (area_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002496 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002497 wlv.char_attr = hl_combine_attr(wlv.line_attr, area_attr);
Bram Moolenaar2d5f3852021-04-21 15:11:42 +02002498 if (!highlight_match)
2499 // let search highlight show in Visual area if possible
Bram Moolenaar1306b362022-08-06 15:59:06 +01002500 wlv.char_attr = hl_combine_attr(search_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002501# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002502 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002503# endif
2504 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002505 else if (search_attr != 0)
Bram Moolenaar84590062019-10-18 23:12:20 +02002506 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002507 wlv.char_attr = hl_combine_attr(wlv.line_attr, search_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002508# ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002509 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.char_attr);
Bram Moolenaar84590062019-10-18 23:12:20 +02002510# endif
2511 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002512 else if (wlv.line_attr != 0
Bram Moolenaarc20a4192022-09-21 14:34:28 +01002513 && ((wlv.fromcol == -10 && wlv.tocol == MAXCOL)
2514 || wlv.vcol < wlv.fromcol
2515 || vcol_prev < fromcol_prev
2516 || wlv.vcol >= wlv.tocol))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002517 {
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002518 // Use wlv.line_attr when not in the Visual or 'incsearch' area
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002519 // (area_attr may be 0 when "noinvcur" is set).
Bram Moolenaar34390282019-10-16 14:38:26 +02002520# ifdef FEAT_SYN_HL
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002521 wlv.char_attr = hl_combine_attr(syntax_attr, wlv.line_attr);
Bram Moolenaardbd43162019-11-09 21:28:14 +01002522# else
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00002523 wlv.char_attr = wlv.line_attr;
Bram Moolenaar34390282019-10-16 14:38:26 +02002524# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002525 attr_pri = FALSE;
2526 }
2527#else
2528 if (area_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002529 wlv.char_attr = area_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002530 else if (search_attr != 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002531 wlv.char_attr = search_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002532#endif
2533 else
2534 {
2535 attr_pri = FALSE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002536#ifdef FEAT_SYN_HL
Bram Moolenaar1306b362022-08-06 15:59:06 +01002537 wlv.char_attr = syntax_attr;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002538#else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002539 wlv.char_attr = 0;
Bram Moolenaara74fda62019-10-19 17:38:03 +02002540#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002541 }
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002542#ifdef FEAT_PROP_POPUP
2543 // override with text property highlight when "override" is TRUE
2544 if (text_prop_type != NULL && (text_prop_flags & PT_FLAG_OVERRIDE))
Bram Moolenaar1306b362022-08-06 15:59:06 +01002545 wlv.char_attr = hl_combine_attr(wlv.char_attr, text_prop_attr);
Bram Moolenaar4d2031f2022-08-05 20:03:55 +01002546#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002547 }
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002548
2549 // combine attribute with 'wincolor'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002550 if (wlv.win_attr != 0)
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002551 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002552 if (wlv.char_attr == 0)
2553 wlv.char_attr = wlv.win_attr;
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002554 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002555 wlv.char_attr = hl_combine_attr(wlv.win_attr, wlv.char_attr);
Bram Moolenaar024dbd22019-11-02 22:00:15 +01002556 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002557
2558 // Get the next character to put on the screen.
2559
2560 // The "p_extra" points to the extra stuff that is inserted to
2561 // represent special characters (non-printable stuff) and other
2562 // things. When all characters are the same, c_extra is used.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002563 // If wlv.c_final is set, it will compulsorily be used at the end.
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002564 // "p_extra" must end in a NUL to avoid mb_ptr2len() reads past
2565 // "p_extra[n_extra]".
2566 // For the '$' of the 'list' option, n_extra == 1, p_extra == "".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002567 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002568 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002569 if (wlv.c_extra != NUL || (wlv.n_extra == 1 && wlv.c_final != NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002570 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002571 c = (wlv.n_extra == 1 && wlv.c_final != NUL)
2572 ? wlv.c_final : wlv.c_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002573 mb_c = c; // doesn't handle non-utf-8 multi-byte!
2574 if (enc_utf8 && utf_char2len(c) > 1)
2575 {
2576 mb_utf8 = TRUE;
2577 u8cc[0] = 0;
2578 c = 0xc0;
2579 }
2580 else
2581 mb_utf8 = FALSE;
2582 }
2583 else
2584 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002585 c = *wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002586 if (has_mbyte)
2587 {
2588 mb_c = c;
2589 if (enc_utf8)
2590 {
2591 // If the UTF-8 character is more than one byte:
2592 // Decode it into "mb_c".
Bram Moolenaar1306b362022-08-06 15:59:06 +01002593 mb_l = utfc_ptr2len(wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002594 mb_utf8 = FALSE;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002595 if (mb_l > wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002596 mb_l = 1;
2597 else if (mb_l > 1)
2598 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002599 mb_c = utfc_ptr2char(wlv.p_extra, u8cc);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002600 mb_utf8 = TRUE;
2601 c = 0xc0;
2602 }
2603 }
2604 else
2605 {
2606 // if this is a DBCS character, put it in "mb_c"
2607 mb_l = MB_BYTE2LEN(c);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002608 if (mb_l >= wlv.n_extra)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002609 mb_l = 1;
2610 else if (mb_l > 1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002611 mb_c = (c << 8) + wlv.p_extra[1];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002612 }
2613 if (mb_l == 0) // at the NUL at end-of-line
2614 mb_l = 1;
2615
2616 // If a double-width char doesn't fit display a '>' in the
2617 // last column.
2618 if ((
2619# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002620 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002621# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002622 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002623 && (*mb_char2cells)(mb_c) == 2)
2624 {
2625 c = '>';
2626 mb_c = c;
2627 mb_l = 1;
2628 mb_utf8 = FALSE;
2629 multi_attr = HL_ATTR(HLF_AT);
2630#ifdef FEAT_SYN_HL
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01002631 if (wlv.cul_attr)
2632 multi_attr = hl_combine_attr(
2633 multi_attr, wlv.cul_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002634#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002635 multi_attr = hl_combine_attr(wlv.win_attr, multi_attr);
Bram Moolenaar92e25ab2019-11-26 22:39:10 +01002636
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002637 // put the pointer back to output the double-width
2638 // character at the start of the next line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01002639 ++wlv.n_extra;
2640 --wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002641 }
2642 else
2643 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002644 wlv.n_extra -= mb_l - 1;
2645 wlv.p_extra += mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002646 }
2647 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002648 ++wlv.p_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002649 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01002650 --wlv.n_extra;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002651#if defined(FEAT_PROP_POPUP)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002652 if (wlv.n_extra <= 0)
Bram Moolenaare38fc862022-08-11 17:24:50 +01002653 {
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00002654 // Only restore search_attr and area_attr after "n_extra" in
2655 // the next screen line is also done.
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002656 if (wlv.saved_n_extra <= 0)
2657 {
2658 if (search_attr == 0)
2659 search_attr = saved_search_attr;
2660 if (area_attr == 0 && *ptr != NUL)
2661 area_attr = saved_area_attr;
Bram Moolenaar637862f2022-11-24 23:04:02 +00002662
2663 if (wlv.extra_for_textprop)
2664 // wlv.extra_attr should be used at this position but
2665 // not any further.
2666 reset_extra_attr = TRUE;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002667 }
Bram Moolenaar637862f2022-11-24 23:04:02 +00002668
2669 wlv.extra_for_textprop = FALSE;
2670 in_linebreak = FALSE;
Bram Moolenaare38fc862022-08-11 17:24:50 +01002671 }
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00002672#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002673 }
2674 else
2675 {
2676#ifdef FEAT_LINEBREAK
Bram Moolenaarb9081882022-07-09 04:56:24 +01002677 int c0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002678#endif
zeertzjqe500ae82023-08-17 22:35:26 +02002679 char_u *prev_ptr = ptr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002680
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002681 // Get a character from the line itself.
2682 c = *ptr;
2683#ifdef FEAT_LINEBREAK
2684 c0 = *ptr;
2685#endif
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002686 if (c == NUL)
zeertzjqb557f482023-08-22 22:07:34 +02002687 {
2688#ifdef FEAT_PROP_POPUP
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002689 // text is finished, may display a "below" virtual text
2690 did_line = TRUE;
2691#endif
zeertzjqb557f482023-08-22 22:07:34 +02002692 // no more cells to skip
2693 skip_cells = 0;
2694 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00002695
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002696 if (has_mbyte)
2697 {
2698 mb_c = c;
2699 if (enc_utf8)
2700 {
2701 // If the UTF-8 character is more than one byte: Decode it
2702 // into "mb_c".
2703 mb_l = utfc_ptr2len(ptr);
2704 mb_utf8 = FALSE;
2705 if (mb_l > 1)
2706 {
2707 mb_c = utfc_ptr2char(ptr, u8cc);
2708 // Overlong encoded ASCII or ASCII with composing char
2709 // is displayed normally, except a NUL.
2710 if (mb_c < 0x80)
2711 {
2712 c = mb_c;
2713#ifdef FEAT_LINEBREAK
2714 c0 = mb_c;
2715#endif
2716 }
2717 mb_utf8 = TRUE;
2718
2719 // At start of the line we can have a composing char.
2720 // Draw it as a space with a composing char.
2721 if (utf_iscomposing(mb_c))
2722 {
2723 int i;
2724
2725 for (i = Screen_mco - 1; i > 0; --i)
2726 u8cc[i] = u8cc[i - 1];
2727 u8cc[0] = mb_c;
2728 mb_c = ' ';
2729 }
2730 }
2731
2732 if ((mb_l == 1 && c >= 0x80)
2733 || (mb_l >= 1 && mb_c == 0)
2734 || (mb_l > 1 && (!vim_isprintc(mb_c))))
2735 {
2736 // Illegal UTF-8 byte: display as <xx>.
2737 // Non-BMP character : display as ? or fullwidth ?.
Bram Moolenaard7657e92022-09-20 18:59:30 +01002738 transchar_hex(wlv.extra, mb_c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002739# ifdef FEAT_RIGHTLEFT
2740 if (wp->w_p_rl) // reverse
Bram Moolenaard7657e92022-09-20 18:59:30 +01002741 rl_mirror(wlv.extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002742# endif
Bram Moolenaard7657e92022-09-20 18:59:30 +01002743 wlv.p_extra = wlv.extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002744 c = *wlv.p_extra;
2745 mb_c = mb_ptr2char_adv(&wlv.p_extra);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002746 mb_utf8 = (c >= 0x80);
Bram Moolenaar1306b362022-08-06 15:59:06 +01002747 wlv.n_extra = (int)STRLEN(wlv.p_extra);
2748 wlv.c_extra = NUL;
2749 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002750 if (area_attr == 0 && search_attr == 0)
2751 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002752 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002753 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002754 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002755 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002756 }
2757 }
2758 else if (mb_l == 0) // at the NUL at end-of-line
2759 mb_l = 1;
2760#ifdef FEAT_ARABIC
2761 else if (p_arshape && !p_tbidi && ARABIC_CHAR(mb_c))
2762 {
2763 // Do Arabic shaping.
2764 int pc, pc1, nc;
2765 int pcc[MAX_MCO];
2766
2767 // The idea of what is the previous and next
2768 // character depends on 'rightleft'.
2769 if (wp->w_p_rl)
2770 {
2771 pc = prev_c;
2772 pc1 = prev_c1;
2773 nc = utf_ptr2char(ptr + mb_l);
2774 prev_c1 = u8cc[0];
2775 }
2776 else
2777 {
2778 pc = utfc_ptr2char(ptr + mb_l, pcc);
2779 nc = prev_c;
2780 pc1 = pcc[0];
2781 }
2782 prev_c = mb_c;
2783
2784 mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc);
2785 }
2786 else
2787 prev_c = mb_c;
2788#endif
2789 }
2790 else // enc_dbcs
2791 {
2792 mb_l = MB_BYTE2LEN(c);
2793 if (mb_l == 0) // at the NUL at end-of-line
2794 mb_l = 1;
2795 else if (mb_l > 1)
2796 {
2797 // We assume a second byte below 32 is illegal.
2798 // Hopefully this is OK for all double-byte encodings!
2799 if (ptr[1] >= 32)
2800 mb_c = (c << 8) + ptr[1];
2801 else
2802 {
2803 if (ptr[1] == NUL)
2804 {
2805 // head byte at end of line
2806 mb_l = 1;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002807 transchar_nonprint(wp->w_buffer, wlv.extra, c);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002808 }
2809 else
2810 {
2811 // illegal tail byte
2812 mb_l = 2;
Bram Moolenaard7657e92022-09-20 18:59:30 +01002813 STRCPY(wlv.extra, "XX");
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002814 }
Bram Moolenaard7657e92022-09-20 18:59:30 +01002815 wlv.p_extra = wlv.extra;
2816 wlv.n_extra = (int)STRLEN(wlv.extra) - 1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01002817 wlv.c_extra = NUL;
2818 wlv.c_final = NUL;
2819 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002820 if (area_attr == 0 && search_attr == 0)
2821 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002822 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002823 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002824 wlv.win_attr, HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002825 // save current attr
2826 saved_attr2 = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002827 }
2828 mb_c = c;
2829 }
2830 }
2831 }
2832 // If a double-width char doesn't fit display a '>' in the
2833 // last column; the character is displayed at the start of the
2834 // next line.
2835 if ((
2836# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002837 wp->w_p_rl ? (wlv.col <= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002838# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002839 (wlv.col >= wp->w_width - 1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002840 && (*mb_char2cells)(mb_c) == 2)
2841 {
2842 c = '>';
2843 mb_c = c;
2844 mb_utf8 = FALSE;
2845 mb_l = 1;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002846 multi_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002847 // Put pointer back so that the character will be
2848 // displayed at the start of the next line.
2849 --ptr;
2850#ifdef FEAT_CONCEAL
2851 did_decrement_ptr = TRUE;
2852#endif
2853 }
2854 else if (*ptr != NUL)
2855 ptr += mb_l - 1;
2856
2857 // If a double-width char doesn't fit at the left side display
2858 // a '<' in the first column. Don't do this for unprintable
2859 // characters.
zeertzjqb557f482023-08-22 22:07:34 +02002860 if (skip_cells > 0 && mb_l > 1 && wlv.n_extra == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002861 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002862 wlv.n_extra = 1;
2863 wlv.c_extra = MB_FILLER_CHAR;
2864 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002865 c = ' ';
2866 if (area_attr == 0 && search_attr == 0)
2867 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01002868 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00002869 wlv.extra_attr = hl_combine_attr(
Bram Moolenaar4d91d342022-08-06 13:48:20 +01002870 wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar1306b362022-08-06 15:59:06 +01002871 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002872 }
2873 mb_c = c;
2874 mb_utf8 = FALSE;
2875 mb_l = 1;
2876 }
2877
2878 }
2879 ++ptr;
2880
2881 if (extra_check)
2882 {
2883#ifdef FEAT_SPELL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002884 // Check spelling (unless at the end of the line).
2885 // Only do this when there is no syntax highlighting, the
2886 // @Spell cluster is not used or the current syntax item
2887 // contains the @Spell cluster.
Bram Moolenaar7751d1d2019-10-18 20:37:08 +02002888 v = (long)(ptr - line);
Luuk van Baal30805a12023-05-27 22:22:10 +01002889 if (spv->spv_has_spell && v >= word_end && v > cur_checked_col)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002890 {
2891 spell_attr = 0;
Christian Brabandtafa23d12022-08-09 12:25:10 +01002892 // do not calculate cap_col at the end of the line or when
2893 // only white space is following
2894 if (c != 0 && (*skipwhite(prev_ptr) != NUL) && (
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002895# ifdef FEAT_SYN_HL
2896 !has_syntax ||
2897# endif
2898 can_spell))
2899 {
Bram Moolenaarb9081882022-07-09 04:56:24 +01002900 char_u *p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002901 int len;
2902 hlf_T spell_hlf = HLF_COUNT;
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01002903
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002904 if (has_mbyte)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002905 v -= mb_l - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002906
2907 // Use nextline[] if possible, it has the start of the
2908 // next line concatenated.
2909 if ((prev_ptr - line) - nextlinecol >= 0)
2910 p = nextline + (prev_ptr - line) - nextlinecol;
2911 else
2912 p = prev_ptr;
Luuk van Baal30805a12023-05-27 22:22:10 +01002913 spv->spv_cap_col -= (int)(prev_ptr - line);
2914 len = spell_check(wp, p, &spell_hlf, &spv->spv_cap_col,
2915 spv->spv_unchanged);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002916 word_end = v + len;
2917
2918 // In Insert mode only highlight a word that
2919 // doesn't touch the cursor.
2920 if (spell_hlf != HLF_COUNT
Bram Moolenaar24959102022-05-07 20:01:16 +01002921 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002922 && wp->w_cursor.lnum == lnum
2923 && wp->w_cursor.col >=
2924 (colnr_T)(prev_ptr - line)
2925 && wp->w_cursor.col < (colnr_T)word_end)
2926 {
2927 spell_hlf = HLF_COUNT;
2928 spell_redraw_lnum = lnum;
2929 }
2930
2931 if (spell_hlf == HLF_COUNT && p != prev_ptr
2932 && (p - nextline) + len > nextline_idx)
2933 {
2934 // Remember that the good word continues at the
2935 // start of the next line.
Luuk van Baal30805a12023-05-27 22:22:10 +01002936 spv->spv_checked_lnum = lnum + 1;
2937 spv->spv_checked_col = (p - nextline) + len
2938 - nextline_idx;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002939 }
2940
2941 // Turn index into actual attributes.
2942 if (spell_hlf != HLF_COUNT)
2943 spell_attr = highlight_attr[spell_hlf];
2944
Luuk van Baal30805a12023-05-27 22:22:10 +01002945 if (spv->spv_cap_col > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002946 {
2947 if (p != prev_ptr
Luuk van Baal30805a12023-05-27 22:22:10 +01002948 && (p - nextline) + spv->spv_cap_col
2949 >= nextline_idx)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002950 {
2951 // Remember that the word in the next line
2952 // must start with a capital.
Luuk van Baal30805a12023-05-27 22:22:10 +01002953 spv->spv_capcol_lnum = lnum + 1;
2954 spv->spv_cap_col = ((p - nextline)
2955 + spv->spv_cap_col - nextline_idx);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002956 }
2957 else
2958 // Compute the actual column.
Luuk van Baal30805a12023-05-27 22:22:10 +01002959 spv->spv_cap_col += (prev_ptr - line);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002960 }
2961 }
2962 }
2963 if (spell_attr != 0)
2964 {
2965 if (!attr_pri)
Bram Moolenaar1306b362022-08-06 15:59:06 +01002966 wlv.char_attr = hl_combine_attr(wlv.char_attr,
2967 spell_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002968 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01002969 wlv.char_attr = hl_combine_attr(spell_attr,
2970 wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002971 }
2972#endif
2973#ifdef FEAT_LINEBREAK
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002974 // we don't want linebreak to apply for lines that start with
2975 // leading spaces, followed by long letters (since it would add
2976 // a break at the beginning of a line and this might be unexpected)
2977 //
2978 // So only allow to linebreak, once we have found chars not in
2979 // 'breakat' in the line.
2980 if ( wp->w_p_lbr && !wlv.need_lbr && c != NUL &&
2981 !VIM_ISBREAK((int)*ptr))
2982 wlv.need_lbr = TRUE;
2983#endif
2984#ifdef FEAT_LINEBREAK
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002985 // Found last space before word: check for line break.
Christian Brabandtdd75fcf2023-10-11 21:51:19 +02002986 if (wp->w_p_lbr && c0 == c && wlv.need_lbr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002987 && VIM_ISBREAK(c) && !VIM_ISBREAK((int)*ptr))
2988 {
Bram Moolenaar20e0c3d2021-08-31 20:57:55 +02002989 int mb_off = has_mbyte ? (*mb_head_off)(line, ptr - 1)
2990 : 0;
2991 char_u *p = ptr - (mb_off + 1);
Bram Moolenaar7f9969c2022-07-25 18:13:54 +01002992 chartabsize_T cts;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02002993
zeertzjqce53e3e2023-09-01 18:49:30 +02002994 init_chartabsize_arg(&cts, wp, lnum, wlv.vcol
2995# ifdef FEAT_PROP_POPUP
2996 - vcol_first_char,
2997# endif
2998 line, p);
Bram Moolenaar52de3a82022-08-10 13:12:03 +01002999# ifdef FEAT_PROP_POPUP
3000 // do not want virtual text counted here
3001 cts.cts_has_prop_with_text = FALSE;
3002# endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003003 wlv.n_extra = win_lbr_chartabsize(&cts, NULL) - 1;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003004 clear_chartabsize_arg(&cts);
Bram Moolenaara06e3452021-05-29 17:56:37 +02003005
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003006 if (on_last_col && c != TAB)
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003007 // Do not continue search/match highlighting over the
Bram Moolenaar0bbca542022-01-11 13:14:54 +00003008 // line break, but for TABs the highlighting should
3009 // include the complete width of the character
Bram Moolenaar0c359af2021-11-29 19:18:57 +00003010 search_attr = 0;
Bram Moolenaara06e3452021-05-29 17:56:37 +02003011
Bram Moolenaar1306b362022-08-06 15:59:06 +01003012 if (c == TAB && wlv.n_extra + wlv.col > wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003013# ifdef FEAT_VARTABS
Bram Moolenaar1306b362022-08-06 15:59:06 +01003014 wlv.n_extra = tabstop_padding(wlv.vcol,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003015 wp->w_buffer->b_p_ts,
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003016 wp->w_buffer->b_p_vts_array) - 1;
3017# else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003018 wlv.n_extra = (int)wp->w_buffer->b_p_ts
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003019 - wlv.vcol % (int)wp->w_buffer->b_p_ts - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003020# endif
3021
Bram Moolenaar1306b362022-08-06 15:59:06 +01003022 wlv.c_extra = mb_off > 0 ? MB_FILLER_CHAR : ' ';
3023 wlv.c_final = NUL;
Bram Moolenaar52de3a82022-08-10 13:12:03 +01003024# ifdef FEAT_PROP_POPUP
Bram Moolenaar1306b362022-08-06 15:59:06 +01003025 if (wlv.n_extra > 0 && c != TAB)
Bram Moolenaar6b839ac2021-11-29 21:12:35 +00003026 in_linebreak = TRUE;
Bram Moolenaar3569c0d2021-12-02 11:34:21 +00003027# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003028 if (VIM_ISWHITE(c))
3029 {
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003030# ifdef FEAT_CONCEAL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003031 if (c == TAB)
3032 // See "Tab alignment" below.
3033 FIX_FOR_BOGUSCOLS;
Bram Moolenaar912bc4a2019-12-01 18:58:11 +01003034# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003035 if (!wp->w_p_list)
3036 c = ' ';
3037 }
3038 }
3039#endif
zeertzjqabc80812023-09-24 23:32:18 +02003040 if (wp->w_p_list)
3041 {
3042 in_multispace = c == ' ' && (*ptr == ' '
3043 || (prev_ptr > line && prev_ptr[-1] == ' '));
3044 if (!in_multispace)
3045 multispace_pos = 0;
3046 }
zeertzjqf14b8ba2021-09-10 16:58:30 +02003047
Bram Moolenaareed9d462021-02-15 20:38:25 +01003048 // 'list': Change char 160 to 'nbsp' and space to 'space'
3049 // setting in 'listchars'. But not when the character is
3050 // followed by a composing character (use mb_l to check that).
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003051 if (wp->w_p_list
3052 && ((((c == 160 && mb_l == 1)
3053 || (mb_utf8
3054 && ((mb_c == 160 && mb_l == 2)
3055 || (mb_c == 0x202f && mb_l == 3))))
Bram Moolenaareed9d462021-02-15 20:38:25 +01003056 && wp->w_lcs_chars.nbsp)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003057 || (c == ' '
3058 && mb_l == 1
zeertzjqf14b8ba2021-09-10 16:58:30 +02003059 && (wp->w_lcs_chars.space
3060 || (in_multispace
3061 && wp->w_lcs_chars.multispace != NULL))
Bram Moolenaar91478ae2021-02-03 15:58:13 +01003062 && ptr - line >= leadcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003063 && ptr - line <= trailcol)))
3064 {
zeertzjqf14b8ba2021-09-10 16:58:30 +02003065 if (in_multispace && wp->w_lcs_chars.multispace != NULL)
3066 {
3067 c = wp->w_lcs_chars.multispace[multispace_pos++];
3068 if (wp->w_lcs_chars.multispace[multispace_pos] == NUL)
3069 multispace_pos = 0;
3070 }
3071 else
3072 c = (c == ' ') ? wp->w_lcs_chars.space
3073 : wp->w_lcs_chars.nbsp;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003074 if (area_attr == 0 && search_attr == 0)
3075 {
3076 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003077 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003078 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003079 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003080 }
3081 mb_c = c;
3082 if (enc_utf8 && utf_char2len(c) > 1)
3083 {
3084 mb_utf8 = TRUE;
3085 u8cc[0] = 0;
3086 c = 0xc0;
3087 }
3088 else
3089 mb_utf8 = FALSE;
3090 }
3091
zeertzjq2e7cba32022-06-10 15:30:32 +01003092 if (c == ' ' && ((trailcol != MAXCOL && ptr > line + trailcol)
3093 || (leadcol != 0 && ptr < line + leadcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003094 {
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003095 if (leadcol != 0 && in_multispace && ptr < line + leadcol
3096 && wp->w_lcs_chars.leadmultispace != NULL)
3097 {
3098 c = wp->w_lcs_chars.leadmultispace[multispace_pos++];
zeertzjq2e7cba32022-06-10 15:30:32 +01003099 if (wp->w_lcs_chars.leadmultispace[multispace_pos]
3100 == NUL)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003101 multispace_pos = 0;
3102 }
3103
3104 else if (ptr > line + trailcol && wp->w_lcs_chars.trail)
3105 c = wp->w_lcs_chars.trail;
3106
3107 else if (ptr < line + leadcol && wp->w_lcs_chars.lead)
3108 c = wp->w_lcs_chars.lead;
3109
zeertzjq2e7cba32022-06-10 15:30:32 +01003110 else if (leadcol != 0 && wp->w_lcs_chars.space)
Bram Moolenaaraca12fd2022-06-07 10:16:15 +01003111 c = wp->w_lcs_chars.space;
3112
3113
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003114 if (!attr_pri)
3115 {
3116 n_attr = 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003117 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003118 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003119 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003120 }
3121 mb_c = c;
3122 if (enc_utf8 && utf_char2len(c) > 1)
3123 {
3124 mb_utf8 = TRUE;
3125 u8cc[0] = 0;
3126 c = 0xc0;
3127 }
3128 else
3129 mb_utf8 = FALSE;
3130 }
3131 }
3132
3133 // Handling of non-printable characters.
3134 if (!vim_isprintc(c))
3135 {
3136 // when getting a character from the file, we may have to
3137 // turn it into something else on the way to putting it
3138 // into "ScreenLines".
Bram Moolenaareed9d462021-02-15 20:38:25 +01003139 if (c == TAB && (!wp->w_p_list || wp->w_lcs_chars.tab1))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003140 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003141 int tab_len = 0;
3142 long vcol_adjusted = wlv.vcol; // removed showbreak len
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003143#ifdef FEAT_LINEBREAK
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003144 char_u *sbr = get_showbreak_value(wp);
Bram Moolenaaree857022019-11-09 23:26:40 +01003145
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003146 // only adjust the tab_len, when at the first column
3147 // after the showbreak value was drawn
Bram Moolenaare49f9ac2022-09-21 15:41:28 +01003148 if (*sbr != NUL && wlv.vcol == wlv.vcol_sbr && wp->w_p_wrap)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003149 vcol_adjusted = wlv.vcol - MB_CHARLEN(sbr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003150#endif
3151 // tab amount depends on current column
3152#ifdef FEAT_VARTABS
3153 tab_len = tabstop_padding(vcol_adjusted,
3154 wp->w_buffer->b_p_ts,
3155 wp->w_buffer->b_p_vts_array) - 1;
3156#else
3157 tab_len = (int)wp->w_buffer->b_p_ts
3158 - vcol_adjusted % (int)wp->w_buffer->b_p_ts - 1;
3159#endif
3160
3161#ifdef FEAT_LINEBREAK
3162 if (!wp->w_p_lbr || !wp->w_p_list)
3163#endif
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003164 {
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003165 // tab amount depends on current column
Bram Moolenaar1306b362022-08-06 15:59:06 +01003166 wlv.n_extra = tab_len;
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003167 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003168#ifdef FEAT_LINEBREAK
3169 else
3170 {
3171 char_u *p;
3172 int len;
3173 int i;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003174 int saved_nextra = wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003175
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003176# ifdef FEAT_CONCEAL
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003177 if (wlv.vcol_off_co > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003178 // there are characters to conceal
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003179 tab_len += wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003180
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003181 // boguscols before FIX_FOR_BOGUSCOLS macro from above
Bram Moolenaareed9d462021-02-15 20:38:25 +01003182 if (wp->w_p_list && wp->w_lcs_chars.tab1
Bram Moolenaar1306b362022-08-06 15:59:06 +01003183 && old_boguscols > 0
3184 && wlv.n_extra > tab_len)
3185 tab_len += wlv.n_extra - tab_len;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003186# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003187 if (tab_len > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003188 {
Bram Moolenaarc67c89c2022-12-02 16:39:44 +00003189 // If wlv.n_extra > 0, it gives the number of chars
3190 // to use for a tab, else we need to calculate the
3191 // width for a tab.
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003192 int tab2_len = mb_char2len(wp->w_lcs_chars.tab2);
3193 len = tab_len * tab2_len;
3194 if (wp->w_lcs_chars.tab3)
3195 len += mb_char2len(wp->w_lcs_chars.tab3)
3196 - tab2_len;
3197 if (wlv.n_extra > 0)
3198 len += wlv.n_extra - tab_len;
3199 c = wp->w_lcs_chars.tab1;
3200 p = alloc(len + 1);
3201 if (p == NULL)
3202 wlv.n_extra = 0;
3203 else
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003204 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003205 vim_memset(p, ' ', len);
3206 p[len] = NUL;
3207 vim_free(wlv.p_extra_free);
3208 wlv.p_extra_free = p;
3209 for (i = 0; i < tab_len; i++)
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003210 {
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003211 int lcs = wp->w_lcs_chars.tab2;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003212
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003213 if (*p == NUL)
3214 {
3215 tab_len = i;
3216 break;
3217 }
3218
3219 // if tab3 is given, use it for the last
3220 // char
3221 if (wp->w_lcs_chars.tab3
3222 && i == tab_len - 1)
3223 lcs = wp->w_lcs_chars.tab3;
3224 p += mb_char2bytes(lcs, p);
3225 wlv.n_extra += mb_char2len(lcs)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003226 - (saved_nextra > 0 ? 1 : 0);
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003227 }
3228 wlv.p_extra = wlv.p_extra_free;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003229# ifdef FEAT_CONCEAL
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003230 // n_extra will be increased by
3231 // FIX_FOX_BOGUSCOLS macro below, so need to
3232 // adjust for that here
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003233 if (wlv.vcol_off_co > 0)
3234 wlv.n_extra -= wlv.vcol_off_co;
Bram Moolenaar89a54b42021-09-07 20:45:31 +02003235# endif
Bram Moolenaar2b7b4f72022-10-08 11:46:02 +01003236 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003237 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003238 }
3239#endif
3240#ifdef FEAT_CONCEAL
3241 {
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003242 int vc_saved = wlv.vcol_off_co;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003243
3244 // Tab alignment should be identical regardless of
3245 // 'conceallevel' value. So tab compensates of all
3246 // previous concealed characters, and thus resets
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003247 // vcol_off_co and boguscols accumulated so far in the
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003248 // line. Note that the tab can be longer than
3249 // 'tabstop' when there are concealed characters.
3250 FIX_FOR_BOGUSCOLS;
3251
3252 // Make sure, the highlighting for the tab char will be
3253 // correctly set further below (effectively reverts the
zeertzjq010e1532024-03-14 18:22:17 +01003254 // FIX_FOR_BOGUSCOLS macro).
Bram Moolenaar1306b362022-08-06 15:59:06 +01003255 if (wlv.n_extra == tab_len + vc_saved && wp->w_p_list
Bram Moolenaareed9d462021-02-15 20:38:25 +01003256 && wp->w_lcs_chars.tab1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003257 tab_len += vc_saved;
3258 }
3259#endif
3260 mb_utf8 = FALSE; // don't draw as UTF-8
3261 if (wp->w_p_list)
3262 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003263 c = (wlv.n_extra == 0 && wp->w_lcs_chars.tab3)
Bram Moolenaareed9d462021-02-15 20:38:25 +01003264 ? wp->w_lcs_chars.tab3
3265 : wp->w_lcs_chars.tab1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003266#ifdef FEAT_LINEBREAK
h-east194555c2023-03-02 18:49:09 +00003267 if (wp->w_p_lbr && wlv.p_extra != NULL
3268 && *wlv.p_extra != NUL)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003269 wlv.c_extra = NUL; // using p_extra from above
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003270 else
3271#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003272 wlv.c_extra = wp->w_lcs_chars.tab2;
3273 wlv.c_final = wp->w_lcs_chars.tab3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003274 n_attr = tab_len + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003275 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003276 HL_ATTR(HLF_8));
Bram Moolenaar1306b362022-08-06 15:59:06 +01003277 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003278 mb_c = c;
3279 if (enc_utf8 && utf_char2len(c) > 1)
3280 {
3281 mb_utf8 = TRUE;
3282 u8cc[0] = 0;
3283 c = 0xc0;
3284 }
3285 }
3286 else
3287 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003288 wlv.c_final = NUL;
3289 wlv.c_extra = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003290 c = ' ';
3291 }
3292 }
3293 else if (c == NUL
Bram Moolenaar234c3fa2023-02-12 14:42:15 +00003294 && wlv.n_extra == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003295 && (wp->w_p_list
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003296 || ((wlv.fromcol >= 0 || fromcol_prev >= 0)
3297 && wlv.tocol > wlv.vcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003298 && VIsual_mode != Ctrl_V
3299 && (
3300# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003301 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003302# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003303 (wlv.col < wp->w_width))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003304 && !(noinvcur
3305 && lnum == wp->w_cursor.lnum
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003306 && (colnr_T)wlv.vcol == wp->w_virtcol)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003307 && lcs_eol_one > 0)
3308 {
3309 // Display a '$' after the line or highlight an extra
3310 // character if the line break is included.
3311#if defined(FEAT_DIFF) || defined(LINE_ATTR)
3312 // For a diff line the highlighting continues after the
3313 // "$".
3314 if (
3315# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003316 wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003317# ifdef LINE_ATTR
3318 &&
3319# endif
3320# endif
3321# ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003322 wlv.line_attr == 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003323# endif
3324 )
3325#endif
3326 {
3327 // In virtualedit, visual selections may extend
3328 // beyond end of line.
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003329 if (!(area_highlighting && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003330 && wlv.tocol != MAXCOL
3331 && wlv.vcol < wlv.tocol))
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01003332 wlv.p_extra = (char_u *)"";
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003333 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003334 }
Bram Moolenaareed9d462021-02-15 20:38:25 +01003335 if (wp->w_p_list && wp->w_lcs_chars.eol > 0)
3336 c = wp->w_lcs_chars.eol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003337 else
3338 c = ' ';
3339 lcs_eol_one = -1;
3340 --ptr; // put it back at the NUL
3341 if (!attr_pri)
3342 {
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003343 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003344 HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003345 n_attr = 1;
3346 }
3347 mb_c = c;
3348 if (enc_utf8 && utf_char2len(c) > 1)
3349 {
3350 mb_utf8 = TRUE;
3351 u8cc[0] = 0;
3352 c = 0xc0;
3353 }
3354 else
3355 mb_utf8 = FALSE; // don't draw as UTF-8
3356 }
3357 else if (c != NUL)
3358 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003359 wlv.p_extra = transchar_buf(wp->w_buffer, c);
3360 if (wlv.n_extra == 0)
3361 wlv.n_extra = byte2cells(c) - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003362#ifdef FEAT_RIGHTLEFT
3363 if ((dy_flags & DY_UHEX) && wp->w_p_rl)
Bram Moolenaar1306b362022-08-06 15:59:06 +01003364 rl_mirror(wlv.p_extra); // reverse "<12>"
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003365#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003366 wlv.c_extra = NUL;
3367 wlv.c_final = NUL;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003368#ifdef FEAT_LINEBREAK
3369 if (wp->w_p_lbr)
3370 {
3371 char_u *p;
3372
Bram Moolenaar1306b362022-08-06 15:59:06 +01003373 c = *wlv.p_extra;
3374 p = alloc(wlv.n_extra + 1);
3375 vim_memset(p, ' ', wlv.n_extra);
3376 STRNCPY(p, wlv.p_extra + 1, STRLEN(wlv.p_extra) - 1);
3377 p[wlv.n_extra] = NUL;
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003378 vim_free(wlv.p_extra_free);
3379 wlv.p_extra_free = wlv.p_extra = p;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003380 }
3381 else
3382#endif
3383 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003384 wlv.n_extra = byte2cells(c) - 1;
3385 c = *wlv.p_extra++;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003386 }
3387 if (!attr_pri)
3388 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003389 n_attr = wlv.n_extra + 1;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003390 wlv.extra_attr = hl_combine_attr(wlv.win_attr,
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003391 HL_ATTR(HLF_8));
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003392#ifdef FEAT_PROP_POPUP
3393 if (text_prop_type != NULL &&
3394 text_prop_flags & PT_FLAG_OVERRIDE)
3395 wlv.extra_attr = hl_combine_attr(text_prop_attr, wlv.extra_attr);
3396#endif
3397
Bram Moolenaar1306b362022-08-06 15:59:06 +01003398 saved_attr2 = wlv.char_attr; // save current attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003399 }
3400 mb_utf8 = FALSE; // don't draw as UTF-8
3401 }
3402 else if (VIsual_active
3403 && (VIsual_mode == Ctrl_V
3404 || VIsual_mode == 'v')
3405 && virtual_active()
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003406 && wlv.tocol != MAXCOL
3407 && wlv.vcol < wlv.tocol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003408 && (
3409#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003410 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003411#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003412 (wlv.col < wp->w_width)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003413 {
3414 c = ' ';
3415 --ptr; // put it back at the NUL
3416 }
3417#if defined(LINE_ATTR)
3418 else if ((
3419# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003420 wlv.diff_hlf != (hlf_T)0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003421# endif
3422# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003423 wlv.win_attr != 0 ||
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003424# endif
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003425 wlv.line_attr != 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003426 ) && (
3427# ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003428 wp->w_p_rl ? (wlv.col >= 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003429# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003430 (wlv.col
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003431# ifdef FEAT_CONCEAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003432 - wlv.boguscols
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003433# endif
3434 < wp->w_width)))
3435 {
3436 // Highlight until the right side of the window
3437 c = ' ';
3438 --ptr; // put it back at the NUL
3439
3440 // Remember we do the char for line highlighting.
3441 ++did_line_attr;
3442
3443 // don't do search HL for the rest of the line
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003444 if (wlv.line_attr != 0 && wlv.char_attr == search_attr
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003445 && (did_line_attr > 1
Bram Moolenaareed9d462021-02-15 20:38:25 +01003446 || (wp->w_p_list &&
3447 wp->w_lcs_chars.eol > 0)))
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003448 wlv.char_attr = wlv.line_attr;
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003449#ifdef FEAT_SIGNS
3450 // At end of line: if Sign is present with line highlight, reset char_attr
Christian Brabandte1eaae22023-08-19 22:36:12 +02003451 // but not when cursorline is active
3452 if (sign_present && wlv.sattr.sat_linehl > 0 && wlv.draw_state == WL_LINE
3453 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum))
Christian Brabandtdbeadf02023-08-19 15:35:04 +02003454 wlv.char_attr = wlv.sattr.sat_linehl;
3455#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003456# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003457 if (wlv.diff_hlf == HLF_TXD)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003458 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003459 wlv.diff_hlf = HLF_CHD;
3460 if (vi_attr == 0 || wlv.char_attr != vi_attr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003461 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003462 wlv.char_attr = HL_ATTR(wlv.diff_hlf);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003463 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3464 && wp->w_p_culopt_flags != CULOPT_NBR
Bram Moolenaar1306b362022-08-06 15:59:06 +01003465 && (!wlv.cul_screenline
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003466 || (wlv.vcol >= left_curline_col
3467 && wlv.vcol <= right_curline_col)))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003468 wlv.char_attr = hl_combine_attr(
3469 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003470 }
3471 }
3472# endif
3473# ifdef FEAT_TERMINAL
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003474 if (wlv.win_attr != 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003475 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003476 wlv.char_attr = wlv.win_attr;
Bram Moolenaara3817732019-10-16 16:31:44 +02003477 if (wp->w_p_cul && lnum == wp->w_cursor.lnum
3478 && wp->w_p_culopt_flags != CULOPT_NBR)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003479 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003480 if (!wlv.cul_screenline
3481 || (wlv.vcol >= left_curline_col
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003482 && wlv.vcol <= right_curline_col))
Bram Moolenaar1306b362022-08-06 15:59:06 +01003483 wlv.char_attr = hl_combine_attr(
3484 wlv.char_attr, HL_ATTR(HLF_CUL));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003485 }
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003486 else if (wlv.line_attr)
3487 wlv.char_attr = hl_combine_attr(
3488 wlv.char_attr, wlv.line_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003489 }
3490# endif
3491 }
3492#endif
3493 }
3494
3495#ifdef FEAT_CONCEAL
3496 if ( wp->w_p_cole > 0
LemonBoy9830db62022-05-08 21:25:20 +01003497 && (wp != curwin || lnum != wp->w_cursor.lnum
3498 || conceal_cursor_line(wp))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003499 && ((syntax_flags & HL_CONCEAL) != 0 || has_match_conc > 0)
3500 && !(lnum_in_visual_area
3501 && vim_strchr(wp->w_p_cocu, 'v') == NULL))
3502 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003503 wlv.char_attr = conceal_attr;
LemonBoy9830db62022-05-08 21:25:20 +01003504 if (((prev_syntax_id != syntax_seqnr
3505 && (syntax_flags & HL_CONCEAL) != 0)
3506 || has_match_conc > 1)
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003507 && (syn_get_sub_char() != NUL
3508 || (has_match_conc && match_conc)
3509 || wp->w_p_cole == 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003510 && wp->w_p_cole != 3)
3511 {
3512 // First time at this concealed item: display one
3513 // character.
Bram Moolenaar211dd3f2020-06-25 20:07:04 +02003514 if (has_match_conc && match_conc)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003515 c = match_conc;
3516 else if (syn_get_sub_char() != NUL)
3517 c = syn_get_sub_char();
Bram Moolenaareed9d462021-02-15 20:38:25 +01003518 else if (wp->w_lcs_chars.conceal != NUL)
3519 c = wp->w_lcs_chars.conceal;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003520 else
3521 c = ' ';
3522
zeertzjq010e1532024-03-14 18:22:17 +01003523 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3524 // When the first char to be concealed is double-width,
3525 // need to advance one more virtual column.
3526 wlv.n_extra++;
3527
3528 mb_c = c;
3529 if (enc_utf8 && utf_char2len(c) > 1)
3530 {
3531 mb_utf8 = TRUE;
3532 u8cc[0] = 0;
3533 c = 0xc0;
3534 }
3535 else
3536 mb_utf8 = FALSE; // don't draw as UTF-8
3537
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003538 prev_syntax_id = syntax_seqnr;
3539
Bram Moolenaar1306b362022-08-06 15:59:06 +01003540 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00003541 wlv.vcol_off_co += wlv.n_extra;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003542 wlv.vcol += wlv.n_extra;
3543 if (wp->w_p_wrap && wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003544 {
3545# ifdef FEAT_RIGHTLEFT
3546 if (wp->w_p_rl)
3547 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003548 wlv.col -= wlv.n_extra;
3549 wlv.boguscols -= wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003550 }
3551 else
3552# endif
3553 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003554 wlv.boguscols += wlv.n_extra;
3555 wlv.col += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003556 }
3557 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003558 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003559 n_attr = 0;
3560 }
zeertzjqb557f482023-08-22 22:07:34 +02003561 else if (skip_cells == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003562 {
3563 is_concealing = TRUE;
zeertzjqb557f482023-08-22 22:07:34 +02003564 skip_cells = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003565 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003566 }
3567 else
3568 {
3569 prev_syntax_id = 0;
3570 is_concealing = FALSE;
3571 }
3572
zeertzjqb557f482023-08-22 22:07:34 +02003573 if (skip_cells > 0 && did_decrement_ptr)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003574 // not showing the '>', put pointer back to avoid getting stuck
3575 ++ptr;
3576
3577#endif // FEAT_CONCEAL
3578 }
3579
3580#ifdef FEAT_CONCEAL
3581 // In the cursor line and we may be concealing characters: correct
3582 // the cursor column when we reach its position.
zeertzjq253ff4d2024-03-13 20:38:26 +01003583 // With 'virtualedit' we may never reach cursor position, but we still
3584 // need to correct the cursor column, so do that at end of line.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003585 if (!did_wcol && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003586 && wp == curwin && lnum == wp->w_cursor.lnum
3587 && conceal_cursor_line(wp)
zeertzjq253ff4d2024-03-13 20:38:26 +01003588 && (wlv.vcol + skip_cells >= wp->w_virtcol || c == NUL))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003589 {
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003590# ifdef FEAT_RIGHTLEFT
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003591 if (wp->w_p_rl)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003592 wp->w_wcol = wp->w_width - wlv.col + wlv.boguscols - 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003593 else
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003594# endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003595 wp->w_wcol = wlv.col - wlv.boguscols;
zeertzjq253ff4d2024-03-13 20:38:26 +01003596 if (wlv.vcol + skip_cells < wp->w_virtcol)
3597 // Cursor beyond end of the line with 'virtualedit'.
3598 wp->w_wcol += wp->w_virtcol - wlv.vcol - skip_cells;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003599 wp->w_wrow = wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003600 did_wcol = TRUE;
3601 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL;
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003602# ifdef FEAT_PROP_POPUP
Bram Moolenaar6a076442020-11-15 20:32:58 +01003603 curwin->w_flags &= ~(WFLAG_WCOL_OFF_ADDED | WFLAG_WROW_OFF_ADDED);
Bram Moolenaar1efefda2020-11-17 19:22:06 +01003604# endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003605 }
3606#endif
3607
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003608 // Use "wlv.extra_attr", but don't override visual selection
3609 // highlighting, unless text property overrides.
Bram Moolenaar37f088e2022-12-02 21:50:14 +00003610 // Don't use "wlv.extra_attr" until wlv.n_attr_skip is zero.
3611 if (wlv.n_attr_skip == 0 && n_attr > 0
Bram Moolenaar1306b362022-08-06 15:59:06 +01003612 && wlv.draw_state == WL_LINE
Bram Moolenaar677a39f2022-08-14 16:50:42 +01003613 && (!attr_pri
3614#ifdef FEAT_PROP_POPUP
3615 || (text_prop_flags & PT_FLAG_OVERRIDE)
3616#endif
3617 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003618 {
3619#ifdef LINE_ATTR
Bram Moolenaar45e4eea2022-12-01 18:38:02 +00003620 if (wlv.line_attr)
3621 wlv.char_attr = hl_combine_attr(wlv.line_attr, wlv.extra_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003622 else
3623#endif
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003624 wlv.char_attr = wlv.extra_attr;
Bram Moolenaar6ac16f02022-11-24 22:42:29 +00003625#ifdef FEAT_PROP_POPUP
3626 if (reset_extra_attr)
3627 {
3628 reset_extra_attr = FALSE;
3629 wlv.extra_attr = 0;
3630 }
3631#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003632 }
3633
3634#if defined(FEAT_XIM) && defined(FEAT_GUI_GTK)
3635 // XIM don't send preedit_start and preedit_end, but they send
3636 // preedit_changed and commit. Thus Vim can't set "im_is_active", use
3637 // im_is_preediting() here.
3638 if (p_imst == IM_ON_THE_SPOT
3639 && xic != NULL
3640 && lnum == wp->w_cursor.lnum
Bram Moolenaar24959102022-05-07 20:01:16 +01003641 && (State & MODE_INSERT)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003642 && !p_imdisable
3643 && im_is_preediting()
Bram Moolenaar1306b362022-08-06 15:59:06 +01003644 && wlv.draw_state == WL_LINE)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003645 {
3646 colnr_T tcol;
3647
3648 if (preedit_end_col == MAXCOL)
3649 getvcol(curwin, &(wp->w_cursor), &tcol, NULL, NULL);
3650 else
3651 tcol = preedit_end_col;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003652 if ((long)preedit_start_col <= wlv.vcol && wlv.vcol < (long)tcol)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003653 {
3654 if (feedback_old_attr < 0)
3655 {
3656 feedback_col = 0;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003657 feedback_old_attr = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003658 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01003659 wlv.char_attr = im_get_feedback_attr(feedback_col);
3660 if (wlv.char_attr < 0)
3661 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003662 feedback_col++;
3663 }
3664 else if (feedback_old_attr >= 0)
3665 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003666 wlv.char_attr = feedback_old_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003667 feedback_old_attr = -1;
3668 feedback_col = 0;
3669 }
3670 }
3671#endif
3672 // Handle the case where we are in column 0 but not on the first
3673 // character of the line and the user wants us to show us a
3674 // special character (via 'listchars' option "precedes:<char>".
3675 if (lcs_prec_todo != NUL
3676 && wp->w_p_list
Bram Moolenaarf6196f42022-10-02 21:29:55 +01003677 && (wp->w_p_wrap ? (wp->w_skipcol > 0 && wlv.row == 0)
3678 : wp->w_leftcol > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003679#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003680 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003681#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003682 && wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003683 && c != NUL)
3684 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003685 c = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003686 lcs_prec_todo = NUL;
3687 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3688 {
3689 // Double-width character being overwritten by the "precedes"
3690 // character, need to fill up half the character.
Bram Moolenaar1306b362022-08-06 15:59:06 +01003691 wlv.c_extra = MB_FILLER_CHAR;
3692 wlv.c_final = NUL;
3693 wlv.n_extra = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003694 n_attr = 2;
Bram Moolenaarfc1b2d02022-11-16 22:12:57 +00003695 wlv.extra_attr =
3696 hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003697 }
3698 mb_c = c;
3699 if (enc_utf8 && utf_char2len(c) > 1)
3700 {
3701 mb_utf8 = TRUE;
3702 u8cc[0] = 0;
3703 c = 0xc0;
3704 }
3705 else
3706 mb_utf8 = FALSE; // don't draw as UTF-8
3707 if (!attr_pri)
3708 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003709 saved_attr3 = wlv.char_attr; // save current attr
3710 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003711 n_attr3 = 1;
3712 }
3713 }
3714
3715 // At end of the text line or just after the last character.
3716 if ((c == NUL
3717#if defined(LINE_ATTR)
3718 || did_line_attr == 1
3719#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003720 ) && wlv.eol_hl_off == 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003721 {
3722#ifdef FEAT_SEARCH_EXTRA
3723 // flag to indicate whether prevcol equals startcol of search_hl or
3724 // one of the matches
3725 int prevcol_hl_flag = get_prevcol_hl_flag(wp, &screen_search_hl,
3726 (long)(ptr - line) - (c == NUL));
3727#endif
3728 // Invert at least one char, used for Visual and empty line or
3729 // highlight match at end of line. If it's beyond the last
3730 // char on the screen, just overwrite that one (tricky!) Not
3731 // needed when a '$' was displayed for 'list'.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003732 if (wp->w_lcs_chars.eol == lcs_eol_one
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003733 && ((area_attr != 0 && wlv.vcol == wlv.fromcol
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003734 && (VIsual_mode != Ctrl_V
3735 || lnum == VIsual.lnum
3736 || lnum == curwin->w_cursor.lnum)
3737 && c == NUL)
3738#ifdef FEAT_SEARCH_EXTRA
3739 // highlight 'hlsearch' match at end of line
3740 || (prevcol_hl_flag
3741# ifdef FEAT_SYN_HL
3742 && !(wp->w_p_cul && lnum == wp->w_cursor.lnum
3743 && !(wp == curwin && VIsual_active))
3744# endif
3745# ifdef FEAT_DIFF
Bram Moolenaar1306b362022-08-06 15:59:06 +01003746 && wlv.diff_hlf == (hlf_T)0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003747# endif
3748# if defined(LINE_ATTR)
3749 && did_line_attr <= 1
3750# endif
3751 )
3752#endif
3753 ))
3754 {
3755 int n = 0;
3756
3757#ifdef FEAT_RIGHTLEFT
3758 if (wp->w_p_rl)
3759 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003760 if (wlv.col < 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003761 n = 1;
3762 }
3763 else
3764#endif
3765 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003766 if (wlv.col >= wp->w_width)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003767 n = -1;
3768 }
3769 if (n != 0)
3770 {
3771 // At the window boundary, highlight the last character
3772 // instead (better than nothing).
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003773 wlv.off += n;
3774 wlv.col += n;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003775 }
3776 else
3777 {
3778 // Add a blank character to highlight.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003779 ScreenLines[wlv.off] = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003780 if (enc_utf8)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003781 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003782 }
3783#ifdef FEAT_SEARCH_EXTRA
3784 if (area_attr == 0)
3785 {
3786 // Use attributes from match with highest priority among
3787 // 'search_hl' and the match list.
3788 get_search_match_hl(wp, &screen_search_hl,
Bram Moolenaar1306b362022-08-06 15:59:06 +01003789 (long)(ptr - line), &wlv.char_attr);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003790 }
3791#endif
Bram Moolenaar1306b362022-08-06 15:59:06 +01003792 ScreenAttrs[wlv.off] = wlv.char_attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01003793 ScreenCols[wlv.off] = wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003794#ifdef FEAT_RIGHTLEFT
3795 if (wp->w_p_rl)
3796 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003797 --wlv.col;
3798 --wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003799 }
3800 else
3801#endif
3802 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003803 ++wlv.col;
3804 ++wlv.off;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003805 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003806 ++wlv.vcol;
3807 wlv.eol_hl_off = 1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003808 }
3809 }
3810
3811 // At end of the text line.
3812 if (c == NUL)
3813 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003814#ifdef FEAT_PROP_POPUP
3815 if (text_prop_follows)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003816 {
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003817 // Put the pointer back to the NUL.
3818 --ptr;
3819 c = ' ';
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003820 }
Bram Moolenaar9d9a20e2023-02-11 13:49:01 +00003821 else
3822#endif
3823 {
3824 draw_screen_line(wp, &wlv);
3825
3826 // Update w_cline_height and w_cline_folded if the cursor line
3827 // was updated (saves a call to plines() later).
3828 if (wp == curwin && lnum == curwin->w_cursor.lnum)
3829 {
3830 curwin->w_cline_row = startrow;
3831 curwin->w_cline_height = wlv.row - startrow;
3832#ifdef FEAT_FOLDING
3833 curwin->w_cline_folded = FALSE;
3834#endif
3835 curwin->w_valid |= (VALID_CHEIGHT|VALID_CROW);
3836 }
3837 break;
3838 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003839 }
3840
3841 // Show "extends" character from 'listchars' if beyond the line end and
3842 // 'list' is set.
Bram Moolenaareed9d462021-02-15 20:38:25 +01003843 if (wp->w_lcs_chars.ext != NUL
Bram Moolenaar1306b362022-08-06 15:59:06 +01003844 && wlv.draw_state == WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003845 && wp->w_p_list
3846 && !wp->w_p_wrap
3847#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003848 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003849#endif
3850 && (
3851#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003852 wp->w_p_rl ? wlv.col == 0 :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003853#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003854 wlv.col == wp->w_width - 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003855 && (*ptr != NUL
Bram Moolenaarc3a483f2022-08-14 19:37:36 +01003856 || lcs_eol_one > 0
3857 || (wlv.n_extra > 0 && (wlv.c_extra != NUL
zeertzjq6a389722023-08-27 19:04:14 +02003858 || *wlv.p_extra != NUL))
3859#ifdef FEAT_PROP_POPUP
zeertzjq4e26a9a2023-12-03 17:50:47 +01003860 || text_prop_next <= last_textprop_text_idx
zeertzjq6a389722023-08-27 19:04:14 +02003861#endif
3862 ))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003863 {
Bram Moolenaareed9d462021-02-15 20:38:25 +01003864 c = wp->w_lcs_chars.ext;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003865 wlv.char_attr = hl_combine_attr(wlv.win_attr, HL_ATTR(HLF_AT));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003866 mb_c = c;
3867 if (enc_utf8 && utf_char2len(c) > 1)
3868 {
3869 mb_utf8 = TRUE;
3870 u8cc[0] = 0;
3871 c = 0xc0;
3872 }
3873 else
3874 mb_utf8 = FALSE;
3875 }
3876
3877#ifdef FEAT_SYN_HL
3878 // advance to the next 'colorcolumn'
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003879 if (wlv.draw_color_col)
3880 wlv.draw_color_col = advance_color_col(VCOL_HLC, &wlv.color_cols);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003881
3882 // Highlight the cursor column if 'cursorcolumn' is set. But don't
3883 // highlight the cursor position itself.
3884 // Also highlight the 'colorcolumn' if it is different than
3885 // 'cursorcolumn'
Bram Moolenaarad5e5632020-09-15 20:52:26 +02003886 // Also highlight the 'colorcolumn' if 'breakindent' and/or 'showbreak'
3887 // options are set
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003888 vcol_save_attr = -1;
Bram Moolenaar1306b362022-08-06 15:59:06 +01003889 if (((wlv.draw_state == WL_LINE
3890 || wlv.draw_state == WL_BRI
3891 || wlv.draw_state == WL_SBR)
3892 && !lnum_in_visual_area
3893 && search_attr == 0
3894 && area_attr == 0)
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003895# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003896 && wlv.filler_todo <= 0
Bram Moolenaarfabc3ca2020-11-05 19:07:21 +01003897# endif
3898 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003899 {
3900 if (wp->w_p_cuc && VCOL_HLC == (long)wp->w_virtcol
3901 && lnum != wp->w_cursor.lnum)
3902 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003903 vcol_save_attr = wlv.char_attr;
3904 wlv.char_attr = hl_combine_attr(wlv.char_attr,
3905 HL_ATTR(HLF_CUC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003906 }
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003907 else if (wlv.draw_color_col && VCOL_HLC == *wlv.color_cols)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003908 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01003909 vcol_save_attr = wlv.char_attr;
3910 wlv.char_attr = hl_combine_attr(wlv.char_attr, HL_ATTR(HLF_MC));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003911 }
3912 }
3913#endif
3914
zeertzjq8fc6a1d2023-08-20 18:12:54 +02003915 if (wlv.draw_state == WL_LINE)
3916 vcol_prev = wlv.vcol;
3917
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003918 // Store character to be displayed.
3919 // Skip characters that are left of the screen for 'nowrap'.
zeertzjqb557f482023-08-22 22:07:34 +02003920 if (wlv.draw_state < WL_LINE || skip_cells <= 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003921 {
3922 // Store the character.
3923#if defined(FEAT_RIGHTLEFT)
3924 if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1)
3925 {
Dominique Pelleaf4a61a2021-12-27 17:21:41 +00003926 // A double-wide character is: put first half in left cell.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003927 --wlv.off;
3928 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003929 }
3930#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003931 ScreenLines[wlv.off] = c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003932 if (enc_dbcs == DBCS_JPNU)
3933 {
3934 if ((mb_c & 0xff00) == 0x8e00)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003935 ScreenLines[wlv.off] = 0x8e;
3936 ScreenLines2[wlv.off] = mb_c & 0xff;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003937 }
3938 else if (enc_utf8)
3939 {
3940 if (mb_utf8)
3941 {
3942 int i;
3943
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003944 ScreenLinesUC[wlv.off] = mb_c;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003945 if ((c & 0xff) == 0)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003946 ScreenLines[wlv.off] = 0x80; // avoid storing zero
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003947 for (i = 0; i < Screen_mco; ++i)
3948 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003949 ScreenLinesC[i][wlv.off] = u8cc[i];
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003950 if (u8cc[i] == 0)
3951 break;
3952 }
3953 }
3954 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003955 ScreenLinesUC[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003956 }
3957 if (multi_attr)
3958 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003959 ScreenAttrs[wlv.off] = multi_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003960 multi_attr = 0;
3961 }
3962 else
Bram Moolenaar1306b362022-08-06 15:59:06 +01003963 ScreenAttrs[wlv.off] = wlv.char_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003964
zeertzjqdb54e982023-09-21 16:33:09 +02003965 if (wlv.draw_state > WL_NR
3966#ifdef FEAT_DIFF
3967 && wlv.filler_todo <= 0
3968#endif
3969 )
3970 ScreenCols[wlv.off] = wlv.vcol;
3971 else
3972 ScreenCols[wlv.off] = -1;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003973
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003974 if (has_mbyte && (*mb_char2cells)(mb_c) > 1)
3975 {
3976 // Need to fill two screen columns.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003977 ++wlv.off;
3978 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003979 if (enc_utf8)
3980 // UTF-8: Put a 0 in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003981 ScreenLines[wlv.off] = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003982 else
3983 // DBCS: Put second byte in the second screen char.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01003984 ScreenLines[wlv.off] = mb_c & 0xff;
zeertzjqdb54e982023-09-21 16:33:09 +02003985
Bram Moolenaar1306b362022-08-06 15:59:06 +01003986 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003987#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01003988 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02003989#endif
3990 )
zeertzjqdb54e982023-09-21 16:33:09 +02003991 ScreenCols[wlv.off] = ++wlv.vcol;
3992 else
3993 ScreenCols[wlv.off] = -1;
3994
Bram Moolenaarc20a4192022-09-21 14:34:28 +01003995 // When "wlv.tocol" is halfway a character, set it to the end
3996 // of the character, otherwise highlighting won't stop.
3997 if (wlv.tocol == wlv.vcol)
3998 ++wlv.tocol;
Bram Moolenaarb9081882022-07-09 04:56:24 +01003999
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004000#ifdef FEAT_RIGHTLEFT
4001 if (wp->w_p_rl)
4002 {
4003 // now it's time to backup one cell
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004004 --wlv.off;
4005 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004006 }
4007#endif
4008 }
4009#ifdef FEAT_RIGHTLEFT
4010 if (wp->w_p_rl)
4011 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004012 --wlv.off;
4013 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004014 }
4015 else
4016#endif
4017 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004018 ++wlv.off;
4019 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004020 }
4021 }
4022#ifdef FEAT_CONCEAL
4023 else if (wp->w_p_cole > 0 && is_concealing)
4024 {
zeertzjq010e1532024-03-14 18:22:17 +01004025 int concealed_wide = has_mbyte && (*mb_char2cells)(mb_c) > 1;
4026
zeertzjqb557f482023-08-22 22:07:34 +02004027 --skip_cells;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004028 ++wlv.vcol_off_co;
zeertzjq010e1532024-03-14 18:22:17 +01004029 if (concealed_wide)
4030 {
4031 // When a double-width char is concealed,
4032 // need to advance one more virtual column.
4033 ++wlv.vcol;
4034 ++wlv.vcol_off_co;
4035 }
4036
Bram Moolenaar1306b362022-08-06 15:59:06 +01004037 if (wlv.n_extra > 0)
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004038 wlv.vcol_off_co += wlv.n_extra;
zeertzjq010e1532024-03-14 18:22:17 +01004039
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004040 if (wp->w_p_wrap)
4041 {
4042 // Special voodoo required if 'wrap' is on.
4043 //
4044 // Advance the column indicator to force the line
4045 // drawing to wrap early. This will make the line
4046 // take up the same screen space when parts are concealed,
4047 // so that cursor line computations aren't messed up.
4048 //
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004049 // To avoid the fictitious advance of 'wlv.col' causing
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004050 // trailing junk to be written out of the screen line
4051 // we are building, 'boguscols' keeps track of the number
4052 // of bad columns we have advanced.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004053 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004054 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004055 wlv.vcol += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004056# ifdef FEAT_RIGHTLEFT
4057 if (wp->w_p_rl)
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 }
4062 else
4063# endif
4064 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004065 wlv.col += wlv.n_extra;
4066 wlv.boguscols += wlv.n_extra;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004067 }
Bram Moolenaar1306b362022-08-06 15:59:06 +01004068 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004069 n_attr = 0;
4070 }
4071
zeertzjq010e1532024-03-14 18:22:17 +01004072 if (concealed_wide)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004073 {
4074 // Need to fill two screen columns.
4075# ifdef FEAT_RIGHTLEFT
4076 if (wp->w_p_rl)
4077 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004078 --wlv.boguscols;
4079 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004080 }
4081 else
4082# endif
4083 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004084 ++wlv.boguscols;
4085 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004086 }
4087 }
4088
4089# ifdef FEAT_RIGHTLEFT
4090 if (wp->w_p_rl)
4091 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004092 --wlv.boguscols;
4093 --wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004094 }
4095 else
4096# endif
4097 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004098 ++wlv.boguscols;
4099 ++wlv.col;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004100 }
4101 }
4102 else
4103 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004104 if (wlv.n_extra > 0)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004105 {
Bram Moolenaar1306b362022-08-06 15:59:06 +01004106 wlv.vcol += wlv.n_extra;
4107 wlv.n_extra = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004108 n_attr = 0;
4109 }
4110 }
4111
4112 }
4113#endif // FEAT_CONCEAL
4114 else
zeertzjqb557f482023-08-22 22:07:34 +02004115 --skip_cells;
4116
4117 if (wlv.draw_state > WL_NR && skipped_cells > 0)
4118 {
4119 wlv.vcol += skipped_cells;
4120 skipped_cells = 0;
4121 }
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004122
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004123 // Only advance the "wlv.vcol" when after the 'number' or
4124 // 'relativenumber' column.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004125 if (wlv.draw_state > WL_NR
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004126#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004127 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004128#endif
4129 )
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004130 ++wlv.vcol;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004131
4132#ifdef FEAT_SYN_HL
4133 if (vcol_save_attr >= 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004134 wlv.char_attr = vcol_save_attr;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004135#endif
4136
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004137 // restore attributes after "precedes" in 'listchars'
Bram Moolenaar1306b362022-08-06 15:59:06 +01004138 if (wlv.draw_state > WL_NR && n_attr3 > 0 && --n_attr3 == 0)
4139 wlv.char_attr = saved_attr3;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004140
4141 // restore attributes after last 'listchars' or 'number' char
Bram Moolenaar1306b362022-08-06 15:59:06 +01004142 if (n_attr > 0 && wlv.draw_state == WL_LINE
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004143 && wlv.n_attr_skip == 0 && --n_attr == 0)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004144 wlv.char_attr = saved_attr2;
Bram Moolenaar37f088e2022-12-02 21:50:14 +00004145 if (wlv.n_attr_skip > 0)
4146 --wlv.n_attr_skip;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004147
4148 // At end of screen line and there is more to come: Display the line
4149 // so far. If there is no more to display it is caught above.
4150 if ((
4151#ifdef FEAT_RIGHTLEFT
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004152 wp->w_p_rl ? (wlv.col < 0) :
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004153#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004154 (wlv.col >= wp->w_width))
Bram Moolenaar1306b362022-08-06 15:59:06 +01004155 && (wlv.draw_state != WL_LINE
Bram Moolenaar41fb7232021-07-08 12:40:05 +02004156 || *ptr != NUL
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004157#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004158 || wlv.filler_todo > 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004159#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004160#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004161 || text_prop_above || text_prop_follows
zeertzjq4e26a9a2023-12-03 17:50:47 +01004162 || text_prop_next <= last_textprop_text_idx
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004163#endif
Bram Moolenaareed9d462021-02-15 20:38:25 +01004164 || (wp->w_p_list && wp->w_lcs_chars.eol != NUL
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004165 && lcs_eol_one != -1)
Bram Moolenaar1306b362022-08-06 15:59:06 +01004166 || (wlv.n_extra != 0 && (wlv.c_extra != NUL
4167 || *wlv.p_extra != NUL)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004168 )
4169 {
4170#ifdef FEAT_CONCEAL
Bram Moolenaar406b5d82022-10-03 16:44:12 +01004171 wlv.col -= wlv.boguscols;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004172 // Apply 'cursorline' and 'wincolor' highlight.
4173 if (wlv.boguscols != 0 && (
4174# ifdef LINE_ATTR
4175 wlv.line_attr != 0 ||
4176# endif
4177 wlv.win_attr != 0
4178 )
4179 )
4180 {
4181 int attr = wlv.win_attr;
4182# ifdef LINE_ATTR
4183 if (wlv.line_attr != 0)
4184 attr = hl_combine_attr(attr, wlv.line_attr);
4185# endif
4186 while ((
4187# ifdef FEAT_RIGHTLEFT
4188 wp->w_p_rl ? wlv.col >= 0 :
4189# endif
4190 wlv.col < wp->w_width))
4191 {
4192 ScreenLines[wlv.off] = ' ';
4193 if (enc_utf8)
4194 ScreenLinesUC[wlv.off] = 0;
4195 ScreenAttrs[wlv.off] = attr;
zeertzjqd0c1b772024-03-16 15:03:33 +01004196 ScreenCols[wlv.off] = wlv.vcol - 1;
zeertzjq21b0a3d2024-03-13 20:06:34 +01004197# ifdef FEAT_RIGHTLEFT
4198 if (wp->w_p_rl)
4199 {
4200 wlv.off--;
4201 wlv.col--;
4202 wlv.boguscols++;
4203 }
4204 else
4205# endif
4206 {
4207 wlv.off++;
4208 wlv.col++;
4209 wlv.boguscols--;
4210 }
4211 }
4212 }
zeertzjqd0c1b772024-03-16 15:03:33 +01004213 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar75008662022-10-04 22:40:56 +01004214 wlv.col += wlv.boguscols;
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004215 wlv.boguscols = 0;
Bram Moolenaarf53e0652023-02-19 14:16:02 +00004216 wlv.vcol_off_co = 0;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004217#else
zeertzjqd0c1b772024-03-16 15:03:33 +01004218 wlv_screen_line(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004219#endif
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004220 ++wlv.row;
4221 ++wlv.screen_row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004222
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004223 // When not wrapping and finished diff lines, break here.
4224 if (!wp->w_p_wrap
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004225#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004226 && wlv.filler_todo <= 0
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004227#endif
4228#ifdef FEAT_PROP_POPUP
Bram Moolenaar877151b2022-10-11 15:29:50 +01004229 && !text_prop_above
Dylan Thacker-Smithf548ae72024-02-24 10:17:11 +01004230 && !text_prop_follows
Bram Moolenaar877151b2022-10-11 15:29:50 +01004231#endif
4232 )
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004233 break;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004234#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004235 if (!wp->w_p_wrap && text_prop_follows && !text_prop_above)
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004236 {
4237 // do not output more of the line, only the "below" prop
4238 ptr += STRLEN(ptr);
4239# ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004240 wlv.dont_use_showbreak = TRUE;
Bram Moolenaar48ca24d2022-08-06 22:03:20 +01004241# endif
4242 }
4243#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004244
4245 // When the window is too narrow draw all "@" lines.
Bram Moolenaar1306b362022-08-06 15:59:06 +01004246 if (wlv.draw_state != WL_LINE
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004247#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004248 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004249#endif
4250 )
4251 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004252 win_draw_end(wp, '@', ' ', TRUE, wlv.row, wp->w_height, HLF_AT);
4253 draw_vsep_win(wp, wlv.row);
4254 wlv.row = endrow;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004255 }
4256
4257 // When line got too long for screen break here.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004258 if (wlv.row == endrow)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004259 {
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004260 ++wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004261 break;
4262 }
4263
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004264 if (screen_cur_row == wlv.screen_row - 1
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004265#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004266 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004267#endif
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004268#ifdef FEAT_PROP_POPUP
Bram Moolenaarc9dc03f2022-09-12 17:51:07 +01004269 && !text_prop_above && !text_prop_follows
Bram Moolenaarb7963df2022-07-31 17:12:43 +01004270#endif
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004271 && wp->w_width == Columns)
4272 {
4273 // Remember that the line wraps, used for modeless copy.
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004274 LineWraps[wlv.screen_row - 1] = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004275
4276 // Special trick to make copy/paste of wrapped lines work with
4277 // xterm/screen: write an extra character beyond the end of
4278 // the line. This will work with all terminal types
4279 // (regardless of the xn,am settings).
4280 // Only do this on a fast tty.
4281 // Only do this if the cursor is on the current line
4282 // (something has been written in it).
4283 // Don't do this for the GUI.
4284 // Don't do this for double-width characters.
4285 // Don't do this for a window not at the right screen border.
4286 if (p_tf
4287#ifdef FEAT_GUI
4288 && !gui.in_use
4289#endif
4290 && !(has_mbyte
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004291 && ((*mb_off2cells)(LineOffset[wlv.screen_row],
4292 LineOffset[wlv.screen_row] + screen_Columns)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004293 == 2
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004294 || (*mb_off2cells)(
4295 LineOffset[wlv.screen_row - 1]
4296 + (int)Columns - 2,
4297 LineOffset[wlv.screen_row]
4298 + screen_Columns) == 2)))
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004299 {
4300 // First make sure we are at the end of the screen line,
4301 // then output the same character again to let the
4302 // terminal know about the wrap. If the terminal doesn't
4303 // auto-wrap, we overwrite the character.
4304 if (screen_cur_col != wp->w_width)
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004305 screen_char(LineOffset[wlv.screen_row - 1]
4306 + (unsigned)Columns - 1,
4307 wlv.screen_row - 1, (int)(Columns - 1));
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004308
4309 // When there is a multi-byte character, just output a
4310 // space to keep it simple.
4311 if (has_mbyte && MB_BYTE2LEN(ScreenLines[LineOffset[
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004312 wlv.screen_row - 1] + (Columns - 1)]) > 1)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004313 out_char(' ');
4314 else
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004315 out_char(ScreenLines[LineOffset[wlv.screen_row - 1]
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004316 + (Columns - 1)]);
4317 // force a redraw of the first char on the next line
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004318 ScreenAttrs[LineOffset[wlv.screen_row]] = (sattr_T)-1;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004319 screen_start(); // don't know where cursor is now
4320 }
4321 }
4322
Bram Moolenaar1306b362022-08-06 15:59:06 +01004323 win_line_start(wp, &wlv, TRUE);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004324
Bram Moolenaareed9d462021-02-15 20:38:25 +01004325 lcs_prec_todo = wp->w_lcs_chars.prec;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004326#ifdef FEAT_LINEBREAK
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004327 if (!wlv.dont_use_showbreak
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004328# ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004329 && wlv.filler_todo <= 0
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004330# endif
Bram Moolenaar3ec3b8e2022-08-05 21:39:30 +01004331 )
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004332 wlv.need_showbreak = TRUE;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004333#endif
4334#ifdef FEAT_DIFF
Bram Moolenaard7657e92022-09-20 18:59:30 +01004335 --wlv.filler_todo;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004336 // When the filler lines are actually below the last line of the
4337 // file, don't draw the line itself, break here.
Bram Moolenaard7657e92022-09-20 18:59:30 +01004338 if (wlv.filler_todo == 0 && wp->w_botfill)
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004339 break;
4340#endif
4341 }
4342
4343 } // for every character in the line
Bram Moolenaar05ad5ff2019-11-30 22:48:27 +01004344#ifdef FEAT_PROP_POPUP
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004345 vim_free(text_props);
4346 vim_free(text_prop_idxs);
Bram Moolenaar1306b362022-08-06 15:59:06 +01004347 vim_free(p_extra_free2);
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004348#endif
4349
Bram Moolenaarc20a4192022-09-21 14:34:28 +01004350 vim_free(wlv.p_extra_free);
zeertzjq58e1e012023-06-04 18:46:28 +01004351 vim_free(wlv.saved_p_extra_free);
Bram Moolenaar4d91d342022-08-06 13:48:20 +01004352 return wlv.row;
Bram Moolenaar7528d1f2019-09-19 23:06:20 +02004353}